88import io .github .Hattinger04 .course .model .course .CourseRepository ;
99import io .github .Hattinger04 .course .model .exercise .Exercise ;
1010import io .github .Hattinger04 .course .model .exercise .ExerciseRepository ;
11+ import io .github .Hattinger04 .course .model .solution .Solution ;
1112import io .github .Hattinger04 .course .model .solution .SolutionRepository ;
1213import io .github .Hattinger04 .user .model .User ;
13- import io .github .Hattinger04 .user .model .UserRepository ;
1414
1515public class CourseService {
1616
@@ -30,8 +30,7 @@ public CourseService(CourseRepository courseRepository, ExerciseRepository exerc
3030
3131 public Course createCourse (String name ) {
3232 Course course = new Course (name );
33- courseRepository .save (course );
34- return course ;
33+ return courseRepository .save (course );
3534 }
3635
3736 public void deleteCourse (String name ) {
@@ -46,6 +45,7 @@ public Course getCourseByName(String name) {
4645 return courseRepository .findByName (name );
4746 }
4847
48+ // TODO: working with student / teacher table
4949 public void addStudentToCourse (Course course , User student ) {
5050
5151 }
@@ -62,21 +62,53 @@ public void removeStudentsFromCourse(Course course, Set<User> student) {
6262
6363 }
6464
65- public Exercise getExerciseByID (int id ) {
66- return exerciseRepository .findById (id );
67- }
68-
65+
6966 // wont work like that ofc
7067 public Exercise createExercise (Integer course_id , String name ) {
7168 Exercise exercise = new Exercise (course_id , name );
72- exerciseRepository .save (exercise );
73- return exercise ;
69+ return exerciseRepository .save (exercise );
70+ }
71+
72+ public Exercise getExerciseByID (int id ) {
73+ return exerciseRepository .findById (id );
74+ }
75+ /**
76+ * Get exercise by course_id and course name
77+ *
78+ * @param course_id
79+ * @param name
80+ * @return
81+ */
82+ public Exercise getExerciseByCourse (int course_id , String name ) {
83+ return exerciseRepository .findByCourse (course_id , name );
7484 }
7585
7686 public void deleteExercise (Integer course_id , String name ) {
7787 exerciseRepository .delete (exerciseRepository .findByCourse (course_id , name ));
7888 }
7989
80- // TODO: students submitting solution
90+
91+ public Solution createSolution (int exercise_id , String text ) {
92+ Solution solution = new Solution (exercise_id , text );
93+ return solutionRepository .save (solution );
94+ }
95+
96+ public Solution getSolutionByID (int id ) {
97+ return solutionRepository .findById (id );
98+ }
99+ /**
100+ * Get solution by exercise_id and exercise name
101+ *
102+ * @param exercise_id
103+ * @param name
104+ * @return
105+ */
106+ public Solution getSolutionByExercise (int exercise_id , String name ) {
107+ return solutionRepository .findByExercise (exercise_id , name );
108+ }
109+
110+ public void deleteSolution (int id ) {
111+ solutionRepository .delete (solutionRepository .findById (id ));
112+ }
81113 // TODO: teacher correcting students work
82114}
0 commit comments