1313import org .springframework .web .bind .annotation .RestController ;
1414
1515import io .github .Hattinger04 .RestServices ;
16- import io .github .Hattinger04 .user .model .User ;
16+ import io .github .Hattinger04 .course .model .CourseService ;
17+ import io .github .Hattinger04 .course .model .course .Course ;
1718import io .github .Hattinger04 .user .model .UserService ;
1819
1920@ RestController
@@ -23,6 +24,8 @@ public class CourseController {
2324 @ Autowired
2425 private UserService userService ;
2526 @ Autowired
27+ private CourseService courseService ;
28+ @ Autowired
2629 private RestServices restServices ;
2730
2831
@@ -36,10 +39,8 @@ public class CourseController {
3639 @ PreAuthorize ("hasAuthority('TEACHER')" )
3740 @ PostMapping ("/getAllStudents" )
3841 @ ResponseBody
39- public ResponseEntity <?> getAllStudents (@ RequestBody String json ) {
40- // TODO: adding to database Course table or smth like that
41- // and return here all students of Course
42- return new ResponseEntity <>(HttpStatus .OK );
42+ public ResponseEntity <?> getAllStudents () {
43+ return new ResponseEntity <>(courseService .getAllStudents (), HttpStatus .OK );
4344 }
4445
4546 /**
@@ -53,7 +54,8 @@ public ResponseEntity<?> getAllStudents(@RequestBody String json) {
5354 @ PutMapping ("/createCourse" )
5455 @ ResponseBody
5556 public ResponseEntity <?> createCourse (@ RequestBody String json ) {
56- // TODO: Create new Course with teacher and students
57+ Course course = (Course ) restServices .deserialize (Course .class , json );
58+ // courseService.createCourse(course);
5759 return new ResponseEntity <>(HttpStatus .OK );
5860 }
5961
@@ -68,7 +70,7 @@ public ResponseEntity<?> createCourse(@RequestBody String json) {
6870 @ DeleteMapping ("/deleteCourse" )
6971 @ ResponseBody
7072 public ResponseEntity <?> deleteCourse (@ RequestBody String json ) {
71- // TODO: deleting existing Course and remove all database entries
73+ // courseService.deleteCourse((Course) restServices.deserialize( Course.class, json););
7274 return new ResponseEntity <>(HttpStatus .OK );
7375 }
7476
@@ -113,7 +115,7 @@ public ResponseEntity<?> removeStudentCourse(@RequestBody String json) {
113115 @ PutMapping ("/createExercise" )
114116 @ ResponseBody
115117 public ResponseEntity <?> createExercise (@ RequestBody String json ) {
116- // TODO: create new exercise for Course
118+ // courseService.createExercise((Exercise) restServices.deserialize(Exercise.class, json););
117119 return new ResponseEntity <>(HttpStatus .OK );
118120 }
119121
@@ -128,7 +130,7 @@ public ResponseEntity<?> createExercise(@RequestBody String json) {
128130 @ PostMapping ("/patchExercise" )
129131 @ ResponseBody
130132 public ResponseEntity <?> patchExercise (@ RequestBody String json ) {
131- // TODO: change exercise for Course
133+ // courseService.createExercise((Exercise) restServices.deserialize(Exercise.class, json););
132134 return new ResponseEntity <>(HttpStatus .OK );
133135 }
134136
@@ -143,7 +145,7 @@ public ResponseEntity<?> patchExercise(@RequestBody String json) {
143145 @ PutMapping ("/deleteExercise" )
144146 @ ResponseBody
145147 public ResponseEntity <?> deleteExercise (@ RequestBody String json ) {
146- // TODO: delete existing exercise
148+ // courseService.deleteExercise((Exercise) restServices.deserialize(Exercise.class, json););
147149 return new ResponseEntity <>(HttpStatus .OK );
148150 }
149151
0 commit comments