1 | package edu.ucsb.cs156.happiercows.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.entities.Student; | |
4 | import edu.ucsb.cs156.happiercows.entities.Courses; | |
5 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.happiercows.repositories.CoursesRepository; | |
7 | import edu.ucsb.cs156.happiercows.repositories.StudentRepository; | |
8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.web.bind.annotation.*; | |
15 | ||
16 | import org.springframework.security.access.prepost.PreAuthorize; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.RequestMapping; | |
19 | import org.springframework.web.bind.annotation.RestController; | |
20 | ||
21 | @Tag(name = "Students") | |
22 | @RequestMapping("/api/students") | |
23 | @RestController | |
24 | @Slf4j | |
25 | public class StudentController extends ApiController { | |
26 | ||
27 | @Autowired | |
28 | StudentRepository studentRepository; | |
29 | ||
30 | @Autowired | |
31 | CoursesRepository coursesRepository; | |
32 | ||
33 | @Operation(summary = "Get student by id") | |
34 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
35 | @GetMapping("") | |
36 | public Student getById(@RequestParam Long id) throws EntityNotFoundException | |
37 | { | |
38 | Student student = studentRepository | |
39 | .findById(id) | |
40 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Student.class, id)); |
41 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::getById → KILLED |
return student; |
42 | } | |
43 | ||
44 | ||
45 | ||
46 | @Operation(summary = "Get all students by course id") | |
47 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
48 | @GetMapping("/course") | |
49 | public Iterable<Student> getByCourseId(@RequestParam Long courseId) throws EntityNotFoundException | |
50 | { | |
51 | Iterable<Student> students = studentRepository.findAllByCourseId(courseId); | |
52 |
1
1. getByCourseId : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::getByCourseId → KILLED |
return students; |
53 | } | |
54 | ||
55 | ||
56 | ||
57 | @Operation(summary= "Delete a student") | |
58 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
59 | @DeleteMapping("") | |
60 | public Object deleteArticle( | |
61 | @RequestParam Long id) throws EntityNotFoundException { | |
62 |
1
1. lambda$deleteArticle$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$deleteArticle$1 → KILLED |
Student student = studentRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Student.class, id)); |
63 | ||
64 |
1
1. deleteArticle : removed call to edu/ucsb/cs156/happiercows/repositories/StudentRepository::delete → KILLED |
studentRepository.delete(student); |
65 |
1
1. deleteArticle : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::deleteArticle → KILLED |
return genericMessage("Student with id %s deleted".formatted(id)); |
66 | } | |
67 | ||
68 | ||
69 | @Operation(summary = "Post a new student") | |
70 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
71 | @PostMapping("") | |
72 | public Student postStudent( | |
73 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
74 | @Parameter(name = "fname") @RequestParam String fname, | |
75 | @Parameter(name = "lname") @RequestParam String lname, | |
76 | @Parameter(name = "studentId") @RequestParam String studentId, | |
77 | @Parameter(name = "email") @RequestParam String email | |
78 | ) { | |
79 | ||
80 |
1
1. lambda$postStudent$2 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$postStudent$2 → KILLED |
coursesRepository.findById(courseId).orElseThrow(() -> new EntityNotFoundException(Courses.class, courseId)); |
81 | ||
82 | Student student = new Student(); | |
83 |
1
1. postStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setCourseId → KILLED |
student.setCourseId(courseId); |
84 |
1
1. postStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setFname → KILLED |
student.setFname(fname); |
85 |
1
1. postStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setLname → KILLED |
student.setLname(lname); |
86 |
1
1. postStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setStudentId → KILLED |
student.setStudentId(studentId); |
87 |
1
1. postStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setEmail → KILLED |
student.setEmail(email); |
88 | | |
89 |
1
1. postStudent : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::postStudent → KILLED |
return studentRepository.save(student); |
90 | ||
91 | } | |
92 | } | |
93 | ||
Mutations | ||
40 |
1.1 |
|
41 |
1.1 |
|
52 |
1.1 |
|
62 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
80 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |