Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Dev stef #228

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.example.codeE.repository;

import com.example.codeE.model.exercise.Exercise;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface ExerciseRepository extends MongoRepository<Exercise, String> {
String getAllExercisesByTopicIdSql = "SELECT * FROM exercise WHERE topic_id = ?1";

@Query(value = getAllExercisesByTopicIdSql, nativeQuery = true)
List<Exercise> getAllExercisesByTopicId(String courseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public interface TopicRepository extends JpaRepository<Topic, String> {
" WHERE student_id = ?1 ))) " +
"AND course_id = ?2 ; ", nativeQuery = true)
List<Topic> getTopicByUser(String studentId, String courseId);

String getTopicByCourseId = "SELECT * FROM codee.topic WHERE course_id = ?1";
List<Topic> findByCourseId(String courseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class ExerciseImpl implements ExerciseService{
private TopicRepository topicRepository;
@Autowired
private FileSubmissionService fileSubmissionService;
@Autowired
private CourseRepository courseRepository;

@Override
public Exercise saveQuizExercise(QuizExercise exercise) {
Expand Down Expand Up @@ -354,7 +356,16 @@ private List<GroupTopicResponse> getGroupResponse(List<String> groupIds) {

@Override
public List<Exercise> getAllExerciseInCourse(String courseId) {
return this.exerciseRepository.findAll();
this.courseRepository.findById(courseId).orElseThrow(() -> new NoSuchElementException("No course found with ID: " + courseId));
List<Topic> topics = topicRepository.findByCourseId(courseId);
List<Exercise> exercises = new ArrayList<>();

for (Topic topic : topics) {
List<Exercise> topicExercises = exerciseRepository.getAllExercisesByTopicId(topic.getTopicId());
exercises.addAll(topicExercises);
}

return exercises;
}

@Override
Expand Down
Loading