1919import io .github .Hattinger04 .course .model .course .Course ;
2020import io .github .Hattinger04 .course .model .exercise .Exercise ;
2121import io .github .Hattinger04 .course .model .student .Student ;
22- import io .github .Hattinger04 .course .model .teacher .Teacher ;
2322import io .github .Hattinger04 .user .model .User ;
2423
2524@ RestController
@@ -100,8 +99,8 @@ public ResponseEntity<?> getCourseTeacher(@RequestBody String json) {
10099 @ PutMapping ("/createCourse" )
101100 @ ResponseBody
102101 public ResponseEntity <?> createCourse (@ RequestBody String json ) {
103- courseService .createCourse ((Course ) restServices .deserialize (Course .class , json ));
104- return new ResponseEntity <>(HttpStatus .OK );
102+ return courseService .createCourse ((Course ) restServices .deserialize (Course .class , json )) != null ?
103+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>( "Could not create course!" , HttpStatus . NOT_IMPLEMENTED );
105104 }
106105
107106 /**
@@ -115,8 +114,8 @@ public ResponseEntity<?> createCourse(@RequestBody String json) {
115114 @ DeleteMapping ("/deleteCourse" )
116115 @ ResponseBody
117116 public ResponseEntity <?> deleteCourse (@ RequestBody String json ) {
118- courseService .deleteCourse ((Course ) restServices .deserialize (Course .class , json ));
119- return new ResponseEntity <>(HttpStatus .OK );
117+ return courseService .deleteCourse ((Course ) restServices .deserialize (Course .class , json )) ?
118+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>( "Could not delete course!" , HttpStatus . NOT_MODIFIED );
120119 }
121120
122121 /**
@@ -130,11 +129,9 @@ public ResponseEntity<?> deleteCourse(@RequestBody String json) {
130129 @ PostMapping ("/addStudentCourse" )
131130 @ ResponseBody
132131 public ResponseEntity <?> addStudentCourse (@ RequestBody String json ) {
133- // TODO: not sure if that will work - probably not
134- Course course = (Course ) restServices .deserialize (Course .class , json );
135- Student student = (Student ) restServices .deserialize (Student .class , json );
136- courseService .addStudentToCourse (course , student );
137- return new ResponseEntity <>(HttpStatus .OK );
132+ Object [] objects = restServices .deserializeMany (new Class [] {Course .class , Student .class }, json );
133+ return courseService .addStudentToCourse ((Course ) objects [0 ], (Student ) objects [1 ]) ?
134+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>("Could not add student to course!" , HttpStatus .NOT_IMPLEMENTED );
138135 }
139136
140137 /**
@@ -148,11 +145,9 @@ public ResponseEntity<?> addStudentCourse(@RequestBody String json) {
148145 @ DeleteMapping ("/removeStudentCourse" )
149146 @ ResponseBody
150147 public ResponseEntity <?> removeStudentCourse (@ RequestBody String json ) {
151- // TODO: not sure if that will work - probably not
152- Course course = (Course ) restServices .deserialize (Course .class , json );
153- Student student = (Student ) restServices .deserialize (Student .class , json );
154- courseService .removeStudentFromCourse (course , student );
155- return new ResponseEntity <>(HttpStatus .OK );
148+ Object [] objects = restServices .deserializeMany (new Class [] {Course .class , Student .class }, json );
149+ return courseService .removeStudentFromCourse ((Course ) objects [0 ], (Student ) objects [1 ]) ?
150+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>("Could not remove student from course!" , HttpStatus .NOT_MODIFIED );
156151 }
157152
158153 /**
@@ -166,8 +161,8 @@ public ResponseEntity<?> removeStudentCourse(@RequestBody String json) {
166161 @ PutMapping ("/createExercise" )
167162 @ ResponseBody
168163 public ResponseEntity <?> createExercise (@ RequestBody String json ) {
169- courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
170- return new ResponseEntity <>(HttpStatus .OK );
164+ return courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json )) != null ?
165+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>( "Could not create exercise!" , HttpStatus . NOT_IMPLEMENTED );
171166 }
172167
173168 /**
@@ -181,8 +176,8 @@ public ResponseEntity<?> createExercise(@RequestBody String json) {
181176 @ PostMapping ("/patchExercise" )
182177 @ ResponseBody
183178 public ResponseEntity <?> patchExercise (@ RequestBody String json ) {
184- courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
185- return new ResponseEntity <>(HttpStatus .OK );
179+ return courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json )) != null ?
180+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>( "Could not patch exercise!" , HttpStatus . NOT_IMPLEMENTED );
186181 }
187182
188183 /**
@@ -196,8 +191,8 @@ public ResponseEntity<?> patchExercise(@RequestBody String json) {
196191 @ PutMapping ("/deleteExercise" )
197192 @ ResponseBody
198193 public ResponseEntity <?> deleteExercise (@ RequestBody String json ) {
199- courseService .deleteExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
200- return new ResponseEntity <>(HttpStatus .OK );
194+ return courseService .deleteExercise ((Exercise ) restServices .deserialize (Exercise .class , json )) ?
195+ new ResponseEntity <>(HttpStatus .OK ) : new ResponseEntity <>( "Could not delete exercise!" , HttpStatus . NOT_IMPLEMENTED );
201196 }
202197
203198 /**
0 commit comments