| 1 | package edu.ucsb.cs156.happiercows.controllers; | |
| 2 | import edu.ucsb.cs156.happiercows.entities.Courses; | |
| 3 | import edu.ucsb.cs156.happiercows.entities.Students; | |
| 4 | import edu.ucsb.cs156.happiercows.repositories.StudentsRepository; | |
| 5 | import edu.ucsb.cs156.happiercows.repositories.CoursesRepository; | |
| 6 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 7 | import lombok.extern.slf4j.Slf4j; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 11 | import org.springframework.web.bind.annotation.GetMapping; | |
| 12 | import org.springframework.web.bind.annotation.PostMapping; | |
| 13 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | import org.springframework.web.bind.annotation.RestController; | |
| 15 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
| 16 | import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | import org.springframework.web.bind.annotation.RequestParam; | |
| 18 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 20 | import org.springframework.web.bind.annotation.PutMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestBody; | |
| 22 | import javax.validation.Valid; | |
| 23 | ||
| 24 | @Tag(name = "Students") | |
| 25 | @RequestMapping("/api/Students") | |
| 26 | @RestController | |
| 27 | @Slf4j | |
| 28 | public class StudentsController extends ApiController { | |
| 29 | ||
| 30 | @Autowired | |
| 31 | StudentsRepository StudentsRepository; | |
| 32 | ||
| 33 | @Autowired | |
| 34 | CoursesRepository coursesRepository; | |
| 35 | /** | |
| 36 | * List all students | |
| 37 | * | |
| 38 | * @return an iterable of Students | |
| 39 | */ | |
| 40 | @Operation(summary= "List all students") | |
| 41 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 42 | @GetMapping("/all") | |
| 43 | public Iterable<Students> allStudents() { | |
| 44 | Iterable<Students> students = StudentsRepository.findAll(); | |
| 45 |
1
1. allStudents : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::allStudents → KILLED |
return students; |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * Create new Student | |
| 50 | * | |
| 51 | * @param lastName last name | |
| 52 | * @param firstMiddleName first and middle name | |
| 53 | * @param email email | |
| 54 | * @param perm Perm number | |
| 55 | * @param courseId course ID | |
| 56 | * @return saved student | |
| 57 | */ | |
| 58 | @Operation(summary= "Create a Student") | |
| 59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 60 | @PostMapping("/post") | |
| 61 | public Students postStudents( | |
| 62 | @Parameter(name = "lastName") @RequestParam String lastName, | |
| 63 | @Parameter(name = "firstMiddleName") @RequestParam String firstMiddleName, | |
| 64 | @Parameter(name = "email") @RequestParam String email, | |
| 65 | @Parameter(name = "perm") @RequestParam String perm, | |
| 66 | @Parameter(name="courseId") @RequestParam Long courseId) | |
| 67 | throws JsonProcessingException { | |
| 68 |
1
1. lambda$postStudents$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::lambda$postStudents$0 → KILLED |
coursesRepository.findById(courseId).orElseThrow(() -> new EntityNotFoundException(Courses.class, courseId)); |
| 69 | Students student = Students.builder() | |
| 70 | .lastName(lastName) | |
| 71 | .firstMiddleName(firstMiddleName) | |
| 72 | .email(email) | |
| 73 | .perm(perm) | |
| 74 | .courseId(courseId) | |
| 75 | .build(); | |
| 76 | Students savedStudents = StudentsRepository.save(student); | |
| 77 |
1
1. postStudents : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::postStudents → KILLED |
return savedStudents; |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Get a student by id | |
| 82 | * | |
| 83 | * @param id the id of the student | |
| 84 | * @return a Student | |
| 85 | */ | |
| 86 | @Operation(summary = "Get a single Student by id") | |
| 87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 88 | @GetMapping("") | |
| 89 | public Students getById( | |
| 90 | @Parameter(name = "id") @RequestParam Long id) { | |
| 91 | Students students = StudentsRepository.findById(id) | |
| 92 |
1
1. lambda$getById$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::lambda$getById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Students.class, id)); |
| 93 | ||
| 94 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::getById → KILLED |
return students; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Update a single Student | |
| 99 | * | |
| 100 | * @param id id of the Student to update | |
| 101 | * @param incoming the new Student | |
| 102 | * @return the updated Students object | |
| 103 | */ | |
| 104 | @Operation(summary= "Update a single Students") | |
| 105 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 106 | @PutMapping("") | |
| 107 | public Students updateStudents( | |
| 108 | @Parameter(name="id") @RequestParam Long id, | |
| 109 | @RequestBody @Valid Students incoming) { | |
| 110 | ||
| 111 | Students student = StudentsRepository.findById(id) | |
| 112 |
1
1. lambda$updateStudents$2 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::lambda$updateStudents$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Students.class, id)); |
| 113 | | |
| 114 |
1
1. updateStudents : removed call to edu/ucsb/cs156/happiercows/entities/Students::setLastName → KILLED |
student.setLastName(incoming.getLastName()); |
| 115 |
1
1. updateStudents : removed call to edu/ucsb/cs156/happiercows/entities/Students::setFirstMiddleName → KILLED |
student.setFirstMiddleName(incoming.getFirstMiddleName()); |
| 116 |
1
1. updateStudents : removed call to edu/ucsb/cs156/happiercows/entities/Students::setEmail → KILLED |
student.setEmail(incoming.getEmail()); |
| 117 |
1
1. updateStudents : removed call to edu/ucsb/cs156/happiercows/entities/Students::setPerm → KILLED |
student.setPerm(incoming.getPerm()); |
| 118 | ||
| 119 | StudentsRepository.save(student); | |
| 120 | ||
| 121 |
1
1. updateStudents : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::updateStudents → KILLED |
return student; |
| 122 | } | |
| 123 | /** | |
| 124 | * Delete a Student | |
| 125 | * | |
| 126 | * @param id the id of the Students to delete | |
| 127 | * @return a message indicating the Students was deleted | |
| 128 | */ | |
| 129 | @Operation(summary = "Delete a Student") | |
| 130 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 131 | @DeleteMapping("") | |
| 132 | public Object deleteStudents( | |
| 133 | @Parameter(name = "id") @RequestParam Long id) { | |
| 134 | Students student = StudentsRepository.findById(id) | |
| 135 |
1
1. lambda$deleteStudents$3 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::lambda$deleteStudents$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Students.class, id)); |
| 136 | ||
| 137 |
1
1. deleteStudents : removed call to edu/ucsb/cs156/happiercows/repositories/StudentsRepository::delete → KILLED |
StudentsRepository.delete(student); |
| 138 |
1
1. deleteStudents : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentsController::deleteStudents → KILLED |
return genericMessage("Student with id %s deleted".formatted(id)); |
| 139 | } | |
| 140 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 68 |
1.1 |
|
| 77 |
1.1 |
|
| 92 |
1.1 |
|
| 94 |
1.1 |
|
| 112 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 116 |
1.1 |
|
| 117 |
1.1 |
|
| 121 |
1.1 |
|
| 135 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |