11package io .github .Hattinger04 .course ;
22
3+ import java .util .List ;
4+
35import org .springframework .beans .factory .annotation .Autowired ;
46import org .springframework .http .HttpStatus ;
57import org .springframework .http .ResponseEntity ;
1719import io .github .Hattinger04 .course .model .course .Course ;
1820import io .github .Hattinger04 .course .model .exercise .Exercise ;
1921import io .github .Hattinger04 .course .model .student .Student ;
22+ import io .github .Hattinger04 .course .model .teacher .Teacher ;
2023
2124@ RestController
2225@ RequestMapping ("/course" )
@@ -42,7 +45,7 @@ public ResponseEntity<?> getStudentByID(@RequestBody String json) {
4245 Object [] objects = restServices .deserializeMany (new Class [] {Course .class , Student .class }, json );
4346 Student student ;
4447 if ((student = courseService .getStudent ((Course )objects [0 ], (Student )objects [1 ])) == null ) {
45- return new ResponseEntity <>("Student not exisiting" , HttpStatus .NOT_FOUND );
48+ return new ResponseEntity <>("Student not exisiting! " , HttpStatus .NOT_FOUND );
4649 }
4750 return new ResponseEntity <>(student , HttpStatus .OK );
4851 }
@@ -59,7 +62,11 @@ public ResponseEntity<?> getStudentByID(@RequestBody String json) {
5962 @ ResponseBody
6063 public ResponseEntity <?> getAllStudents (@ RequestBody String json ) {
6164 Course course = (Course ) restServices .deserialize (Course .class , json );
62- return new ResponseEntity <>(courseService .getAllStudents (course ), HttpStatus .OK );
65+ List <Student > students ;
66+ if ((students = courseService .getAllStudents (course )) == null ) {
67+ return new ResponseEntity <>("Course not existing or no users in course!" , HttpStatus .NOT_FOUND );
68+ }
69+ return new ResponseEntity <>(students , HttpStatus .OK );
6370 }
6471
6572 /**
@@ -74,7 +81,11 @@ public ResponseEntity<?> getAllStudents(@RequestBody String json) {
7481 @ ResponseBody
7582 public ResponseEntity <?> getCourseTeacher (@ RequestBody String json ) {
7683 Course course = (Course ) restServices .deserialize (Course .class , json );
77- return new ResponseEntity <>(courseService .getCourseTeacher (course ), HttpStatus .OK );
84+ Teacher teacher ;
85+ if ((teacher = courseService .getCourseTeacher (course )) == null ) {
86+ return new ResponseEntity <>("Teacher is not in course!" , HttpStatus .NOT_FOUND );
87+ }
88+ return new ResponseEntity <>(teacher , HttpStatus .OK );
7889 }
7990
8091 /**
0 commit comments