Skip to content

Commit 3aeeae1

Browse files
author
Hattinger04
committed
starting to write rest services for course
1 parent cfb1d80 commit 3aeeae1

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/main/java/io/github/Hattinger04/course/CourseController.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import org.springframework.web.bind.annotation.RestController;
1414

1515
import 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;
1718
import 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

src/main/java/io/github/Hattinger04/course/model/CourseService.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.Hattinger04.course.model;
22

3+
import java.util.List;
34
import java.util.Set;
45

56
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,14 +28,11 @@ public CourseService(CourseRepository courseRepository, ExerciseRepository exerc
2728
this.solutionRepository = solutionRepository;
2829
}
2930

30-
31-
// public Course createCourse(String name) {
32-
// Course course = new Course(name);
31+
// public Course createCourse(Course course) {
3332
// return courseRepository.save(course);
3433
// }
35-
//
36-
// public void deleteCourse(String name) {
37-
// courseRepository.delete(courseRepository.findByName(name));
34+
// public void deleteCourse(Course course) {
35+
// courseRepository.delete(course);
3836
// }
3937

4038
public Course getCourseByID(int id) {
@@ -45,6 +43,11 @@ public Course getCourseByName(String name) {
4543
return courseRepository.findByName(name);
4644
}
4745

46+
public List<Student> getAllStudents() {
47+
// TODO: Get all students
48+
return null;
49+
}
50+
4851
// TODO: working with student / teacher table
4952
public void addStudentToCourse(Course course, User student) {
5053

@@ -63,10 +66,11 @@ public void removeStudentsFromCourse(Course course, Set<User> student) {
6366
}
6467

6568

66-
// wont work like that ofc
67-
// public Exercise createExercise(Integer course_id, String name) {
68-
// Exercise exercise = new Exercise(course_id, name);
69+
// public Exercise createExercise(Exercise exercise) {
6970
// return exerciseRepository.save(exercise);
71+
// }
72+
// public void deleteExercise(Exercise exercise) {
73+
// exerciseRepository.delete(exercise);
7074
// }
7175

7276
public Exercise getExerciseByID(int id) {
@@ -83,16 +87,16 @@ public Exercise getExerciseByCourse(int course_id, String name) {
8387
return exerciseRepository.findByCourse(course_id, name);
8488
}
8589

86-
// public void deleteExercise(Integer course_id, String name) {
87-
// exerciseRepository.delete(exerciseRepository.findByCourse(course_id, name));
88-
// }
90+
8991
//
9092
//
91-
// public Solution createSolution(int exercise_id, String text) {
92-
// Solution solution = new Solution(exercise_id, text);
93+
// public Solution createSolution(Solution solution) {
9394
// return solutionRepository.save(solution);
9495
// }
95-
96+
// public void deleteSolution(Solution solution) {
97+
// solutionRepository.delete(solution);
98+
// }
99+
96100
public Solution getSolutionByID(int id) {
97101
return solutionRepository.findById(id);
98102
}
@@ -107,8 +111,5 @@ public Solution getSolutionByExercise(int exercise_id, String name) {
107111
return solutionRepository.findByExercise(exercise_id, name);
108112
}
109113

110-
// public void deleteSolution(int id) {
111-
// solutionRepository.delete(solutionRepository.findById(id));
112-
// }
113114
// TODO: teacher correcting students work
114115
}

src/main/resources/allLogs.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,5 @@ Juli 09, 2022 1:14:40 PM io.github.Hattinger04.aop.LogAspect loginLog
294294
FEIN: User(id=null, username=asdhkla, password=hjkldfsajöd, active=null, roles=null) - [logged in]
295295
Aug. 27, 2022 8:05:52 PM io.github.Hattinger04.aop.LogAspect loginLog
296296
FEIN: User(id=null, username=admin, password=admin, active=null, roles=null) - [logged in]
297+
Aug. 27, 2022 8:16:35 PM io.github.Hattinger04.aop.LogAspect loginLog
298+
FEIN: User(id=null, username=admin, password=admin, active=null, roles=null) - [logged in]

0 commit comments

Comments
 (0)