Skip to content

Commit ab578c2

Browse files
author
Hattinger04
committed
better rest services
1 parent d6f4a0e commit ab578c2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.Hattinger04.course;
22

3+
import java.util.List;
4+
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.http.HttpStatus;
57
import org.springframework.http.ResponseEntity;
@@ -17,6 +19,7 @@
1719
import io.github.Hattinger04.course.model.course.Course;
1820
import io.github.Hattinger04.course.model.exercise.Exercise;
1921
import 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
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class CourseService {
2323

2424
// TODO: Nothing(!) tested yet
25+
// TODO: making void - boolean
2526

2627
private CourseRepository courseRepository;
2728
private ExerciseRepository exerciseRepository;

0 commit comments

Comments
 (0)