1515import io .github .Hattinger04 .RestServices ;
1616import io .github .Hattinger04 .course .model .CourseService ;
1717import io .github .Hattinger04 .course .model .course .Course ;
18+ import io .github .Hattinger04 .course .model .exercise .Exercise ;
19+ import io .github .Hattinger04 .course .model .student .Student ;
1820
1921@ RestController
20- @ RequestMapping ("/USER " )
22+ @ RequestMapping ("/TEACHER " )
2123public class CourseController {
2224
2325 @ Autowired
@@ -26,7 +28,22 @@ public class CourseController {
2628 private RestServices restServices ;
2729
2830
29- // TODO: change hasAuthority('USER') to smth with teacher / student check
31+ /**
32+ * Get student by id in Course from database
33+ * Needs course object
34+ *
35+ * @param json
36+ * @return
37+ */
38+ @ PreAuthorize ("hasAuthority('TEACHER')" )
39+ @ PostMapping ("/getStudentByID" )
40+ @ ResponseBody
41+ public ResponseEntity <?> getStudentByID (@ RequestBody String json ) {
42+ // TODO: not sure if that will work - probably not
43+ Course course = (Course ) restServices .deserialize (Course .class , json );
44+ Student student = (Student ) restServices .deserialize (Student .class , json );
45+ return new ResponseEntity <>(courseService .getStudent (course , student ), HttpStatus .OK );
46+ }
3047
3148 /**
3249 * Get all students in Course from database
@@ -35,26 +52,41 @@ public class CourseController {
3552 * @param json
3653 * @return
3754 */
38- @ PreAuthorize ("hasAuthority('USER ')" )
55+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
3956 @ PostMapping ("/getAllStudents" )
4057 @ ResponseBody
4158 public ResponseEntity <?> getAllStudents (@ RequestBody String json ) {
4259 Course course = (Course ) restServices .deserialize (Course .class , json );
4360 return new ResponseEntity <>(courseService .getAllStudents (course ), HttpStatus .OK );
4461 }
4562
63+ /**
64+ * Get all students in Course from database
65+ * Needs course object
66+ *
67+ * @param json
68+ * @return
69+ */
70+ @ PreAuthorize ("hasAuthority('TEACHER')" )
71+ @ PostMapping ("/getAllStudents" )
72+ @ ResponseBody
73+ public ResponseEntity <?> getCourseTeacher (@ RequestBody String json ) {
74+ Course course = (Course ) restServices .deserialize (Course .class , json );
75+ return new ResponseEntity <>(courseService .getCourseTeacher (course ), HttpStatus .OK );
76+ }
77+
4678 /**
4779 * Create a new Course
4880 * Needs course object
4981 *
5082 * @param json
5183 * @return
5284 */
53- @ PreAuthorize ("hasAuthority('USER ')" )
85+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
5486 @ PutMapping ("/createCourse" )
5587 @ ResponseBody
5688 public ResponseEntity <?> createCourse (@ RequestBody String json ) {
57- // courseService.createCourse((Course) restServices.deserialize(Course.class, json));
89+ courseService .createCourse ((Course ) restServices .deserialize (Course .class , json ));
5890 return new ResponseEntity <>(HttpStatus .OK );
5991 }
6092
@@ -65,11 +97,11 @@ public ResponseEntity<?> createCourse(@RequestBody String json) {
6597 * @param json
6698 * @return
6799 */
68- @ PreAuthorize ("hasAuthority('USER ')" )
100+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
69101 @ DeleteMapping ("/deleteCourse" )
70102 @ ResponseBody
71103 public ResponseEntity <?> deleteCourse (@ RequestBody String json ) {
72- // courseService.deleteCourse((Course) restServices.deserialize(Course.class, json); );
104+ courseService .deleteCourse ((Course ) restServices .deserialize (Course .class , json ));
73105 return new ResponseEntity <>(HttpStatus .OK );
74106 }
75107
@@ -80,11 +112,14 @@ public ResponseEntity<?> deleteCourse(@RequestBody String json) {
80112 * @param json
81113 * @return
82114 */
83- @ PreAuthorize ("hasAuthority('USER ')" )
115+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
84116 @ PostMapping ("/addStudentCourse" )
85117 @ ResponseBody
86118 public ResponseEntity <?> addStudentCourse (@ RequestBody String json ) {
87- // TODO: adding students to Course
119+ // TODO: not sure if that will work - probably not
120+ Course course = (Course ) restServices .deserialize (Course .class , json );
121+ Student student = (Student ) restServices .deserialize (Student .class , json );
122+ courseService .addStudentToCourse (course , student );
88123 return new ResponseEntity <>(HttpStatus .OK );
89124 }
90125
@@ -95,11 +130,14 @@ public ResponseEntity<?> addStudentCourse(@RequestBody String json) {
95130 * @param json
96131 * @return
97132 */
98- @ PreAuthorize ("hasAuthority('USER ')" )
133+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
99134 @ DeleteMapping ("/removeStudentCourse" )
100135 @ ResponseBody
101136 public ResponseEntity <?> removeStudentCourse (@ RequestBody String json ) {
102- // TODO: removing students from Course
137+ // TODO: not sure if that will work - probably not
138+ Course course = (Course ) restServices .deserialize (Course .class , json );
139+ Student student = (Student ) restServices .deserialize (Student .class , json );
140+ courseService .removeStudentFromCourse (course , student );
103141 return new ResponseEntity <>(HttpStatus .OK );
104142 }
105143
@@ -110,11 +148,11 @@ public ResponseEntity<?> removeStudentCourse(@RequestBody String json) {
110148 * @param json
111149 * @return
112150 */
113- @ PreAuthorize ("hasAuthority('USER ')" )
151+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
114152 @ PutMapping ("/createExercise" )
115153 @ ResponseBody
116154 public ResponseEntity <?> createExercise (@ RequestBody String json ) {
117- // courseService.createExercise((Exercise) restServices.deserialize(Exercise.class, json); );
155+ courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
118156 return new ResponseEntity <>(HttpStatus .OK );
119157 }
120158
@@ -125,11 +163,11 @@ public ResponseEntity<?> createExercise(@RequestBody String json) {
125163 * @param json
126164 * @return
127165 */
128- @ PreAuthorize ("hasAuthority('USER ')" )
166+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
129167 @ PostMapping ("/patchExercise" )
130168 @ ResponseBody
131169 public ResponseEntity <?> patchExercise (@ RequestBody String json ) {
132- // courseService.createExercise((Exercise) restServices.deserialize(Exercise.class, json); );
170+ courseService .createExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
133171 return new ResponseEntity <>(HttpStatus .OK );
134172 }
135173
@@ -140,11 +178,11 @@ public ResponseEntity<?> patchExercise(@RequestBody String json) {
140178 * @param json
141179 * @return
142180 */
143- @ PreAuthorize ("hasAuthority('USER ')" )
181+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
144182 @ PutMapping ("/deleteExercise" )
145183 @ ResponseBody
146184 public ResponseEntity <?> deleteExercise (@ RequestBody String json ) {
147- // courseService.deleteExercise((Exercise) restServices.deserialize(Exercise.class, json); );
185+ courseService .deleteExercise ((Exercise ) restServices .deserialize (Exercise .class , json ));
148186 return new ResponseEntity <>(HttpStatus .OK );
149187 }
150188
@@ -155,7 +193,7 @@ public ResponseEntity<?> deleteExercise(@RequestBody String json) {
155193 * @param json
156194 * @return
157195 */
158- @ PreAuthorize ("hasAuthority('USER ')" )
196+ @ PreAuthorize ("hasAuthority('TEACHER ')" )
159197 @ PostMapping ("/rateExercise" )
160198 @ ResponseBody
161199 public ResponseEntity <?> rateExercise (@ RequestBody String json ) {
0 commit comments