Skip to content

Commit 5e52db3

Browse files
author
Hattinger04
committed
continuing on new design
1 parent 9d58fd6 commit 5e52db3

File tree

7 files changed

+67
-24
lines changed

7 files changed

+67
-24
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
@RequestMapping("/USER")
2222
public class CourseController {
2323

24-
@Autowired
25-
private UserService userService;
2624
@Autowired
2725
private CourseService courseService;
2826
@Autowired
@@ -33,21 +31,22 @@ public class CourseController {
3331

3432
/**
3533
* Get all students in Course from database
36-
* Needs Course name
34+
* Needs course object
3735
*
3836
* @param json
3937
* @return
4038
*/
4139
@PreAuthorize("hasAuthority('USER')")
4240
@PostMapping("/getAllStudents")
4341
@ResponseBody
44-
public ResponseEntity<?> getAllStudents() {
45-
return new ResponseEntity<>(courseService.getAllStudents(), HttpStatus.OK);
42+
public ResponseEntity<?> getAllStudents(@RequestBody String json) {
43+
Course course = (Course) restServices.deserialize(Course.class, json);
44+
return new ResponseEntity<>(courseService.getAllStudents(course), HttpStatus.OK);
4645
}
4746

4847
/**
4948
* Create a new Course
50-
* Needs Course name
49+
* Needs course object
5150
*
5251
* @param json
5352
* @return
@@ -56,13 +55,13 @@ public ResponseEntity<?> getAllStudents() {
5655
@PutMapping("/createCourse")
5756
@ResponseBody
5857
public ResponseEntity<?> createCourse(@RequestBody String json) {
59-
// courseService.createCourse((Course) restServices.deserialize(Course.class, json););
58+
// courseService.createCourse((Course) restServices.deserialize(Course.class, json));
6059
return new ResponseEntity<>(HttpStatus.OK);
6160
}
6261

6362
/**
6463
* Deletes a existing Course
65-
* Needs Course name
64+
* Needs course object
6665
*
6766
* @param json
6867
* @return
@@ -77,7 +76,7 @@ public ResponseEntity<?> deleteCourse(@RequestBody String json) {
7776

7877
/**
7978
* Adds student to existing Course
80-
* Needs Course name + student name
79+
* Needs course object + student object
8180
*
8281
* @param json
8382
* @return
@@ -92,7 +91,7 @@ public ResponseEntity<?> addStudentCourse(@RequestBody String json) {
9291

9392
/**
9493
* Removes student from Course
95-
* Needs Course name + student name
94+
* Needs course object + student object
9695
*
9796
* @param json
9897
* @return
@@ -107,7 +106,7 @@ public ResponseEntity<?> removeStudentCourse(@RequestBody String json) {
107106

108107
/**
109108
* Creates a new exercise in a existing Course
110-
* Needs Course name + exercise object
109+
* Needs course object + exercise object
111110
*
112111
* @param json
113112
* @return
@@ -122,7 +121,7 @@ public ResponseEntity<?> createExercise(@RequestBody String json) {
122121

123122
/**
124123
* Changes already existing (and published) exercises
125-
* Needs Course name + exercise object
124+
* Needs course object + exercise object
126125
*
127126
* @param json
128127
* @return
@@ -137,7 +136,7 @@ public ResponseEntity<?> patchExercise(@RequestBody String json) {
137136

138137
/**
139138
* Deletes existing exercise
140-
* Needs Course name + exercise name
139+
* Needs course object + exercise object
141140
*
142141
* @param json
143142
* @return
@@ -152,7 +151,7 @@ public ResponseEntity<?> deleteExercise(@RequestBody String json) {
152151

153152
/**
154153
* Gives a rating to an exercise for one student
155-
* Needs Course name + exercise name + student name
154+
* Needs course object + exercise object + student object
156155
*
157156
* @param json
158157
* @return

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import io.github.Hattinger04.course.model.exercise.ExerciseRepository;
1313
import io.github.Hattinger04.course.model.solution.Solution;
1414
import io.github.Hattinger04.course.model.solution.SolutionRepository;
15+
import io.github.Hattinger04.course.model.student.Student;
16+
import io.github.Hattinger04.course.model.teacher.Teacher;
1517
import io.github.Hattinger04.user.model.User;
1618

1719
@Service
@@ -45,28 +47,48 @@ public Course getCourseByName(String name) {
4547
return courseRepository.findByName(name);
4648
}
4749

48-
public List<Student> getAllStudents() {
49-
// TODO: Get all students
50-
return null;
50+
public List<Student> getAllStudents(Course course) {
51+
return courseRepository.getAllStudents(course.getId());
52+
}
53+
54+
public Teacher getCourseTeacher(Course course) {
55+
// TODO
56+
return null;
57+
}
58+
59+
public void setCourseTeacher(Course course, Teacher teacher) {
60+
5161
}
5262

5363
// TODO: working with student / teacher table
54-
public void addStudentToCourse(Course course, User student) {
64+
public void addStudentToCourse(Course course, Student student) {
5565

5666
}
5767

58-
public void addStudentsToCourse(Course course, Set<User> student) {
68+
public void addStudentsToCourse(Course course, Set<Student> student) {
5969

6070
}
6171

62-
public void removeStudentFromCourse(Course course, User student) {
72+
public void removeStudentFromCourse(Course course, Student student) {
6373

6474
}
6575

66-
public void removeStudentsFromCourse(Course course, Set<User> student) {
76+
public void removeStudentsFromCourse(Course course, Set<Student> student) {
6777

6878
}
6979

80+
public boolean isUserTeacher(Course course, User user) {
81+
if(isUserInCourse(course, user)) {
82+
// TODO
83+
return true;
84+
}
85+
return false;
86+
}
87+
88+
public boolean isUserInCourse(Course course, User user) {
89+
// TODO
90+
return false;
91+
}
7092

7193
public Exercise createExercise(Exercise exercise) {
7294
return exerciseRepository.save(exercise);
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package io.github.Hattinger04.course.model.course;
22

3+
import java.util.List;
4+
35
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.jpa.repository.Query;
47
import org.springframework.stereotype.Repository;
58

9+
import io.github.Hattinger04.course.model.student.Student;
10+
611
@Repository
712
public interface CourseRepository extends JpaRepository<Course, Long>{
813
Course findById(int id);
9-
Course findByName(String name);
14+
Course findByName(String name);
15+
// TODO: SQL not tested yet!
16+
@Query(value = "SELECT * FROM STUDENTS s JOIN USER u using(user_id) JOIN course c using(course_id, user_id) where c.course_id=:course_id", nativeQuery = true)
17+
List<Student> getAllStudents(int course_id);
1018
}

src/main/java/io/github/Hattinger04/course/model/Student.java renamed to src/main/java/io/github/Hattinger04/course/model/student/Student.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.Hattinger04.course.model;
1+
package io.github.Hattinger04.course.model.student;
22

33
import javax.persistence.Column;
44
import javax.persistence.Entity;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.Hattinger04.course.model.student;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
public interface StudentRepository extends JpaRepository<Student, Long>{
6+
Student findById(int id);
7+
}

src/main/java/io/github/Hattinger04/course/model/Teacher.java renamed to src/main/java/io/github/Hattinger04/course/model/teacher/Teacher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.Hattinger04.course.model;
1+
package io.github.Hattinger04.course.model.teacher;
22

33
import javax.persistence.Column;
44
import javax.persistence.Entity;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.Hattinger04.course.model.teacher;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
public interface TeacherRepository extends JpaRepository<Teacher, Long>{
6+
Teacher findById(int id);
7+
}

0 commit comments

Comments
 (0)