StudentController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import edu.ucsb.cs156.happiercows.entities.Student;
4
import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.happiercows.models.StudentDTO;
6
import edu.ucsb.cs156.happiercows.repositories.StudentRepository;
7
import io.swagger.v3.oas.annotations.tags.Tag;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import lombok.extern.slf4j.Slf4j;
11
import jakarta.validation.Valid;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.*;
15
16
@Slf4j
17
@Tag(name = "Student")
18
@RequestMapping("/api/student")
19
@RestController
20
public class StudentController extends ApiController {
21
    @Autowired
22
    private StudentRepository studentRepository;
23
24
    /**
25
     * This method returns a list of all students.
26
     * 
27
     * @return a list of all students
28
     */
29
    @Operation(summary = "List all students")
30
    @PreAuthorize("hasRole('ROLE_USER')")
31
    @GetMapping("/all")
32
    public Iterable<Student> allStudents() {
33
        Iterable<Student> students = studentRepository.findAll();
34 1 1. allStudents : replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/StudentController::allStudents → KILLED
        return students;
35
    }
36
37
    @Operation(summary = "Get a student by id")
38
    @PreAuthorize("hasRole('ROLE_ADMIN')")
39
    @GetMapping("/{id}")
40
    public Student getStudentById(
41
            @Parameter(name = "id") @PathVariable Long id) {
42
        Student student = studentRepository.findById(id)
43 1 1. lambda$getStudentById$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$getStudentById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Student.class, id));
44 1 1. getStudentById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::getStudentById → KILLED
        return student;
45
    }
46
47
    @Operation(summary = "Create a student")
48
    @PreAuthorize("hasRole('ROLE_ADMIN')")
49
    @PostMapping("")
50
    public Student postStudent(@Parameter(name = "student") @RequestBody StudentDTO studentDTO) {
51 1 1. postStudent : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::postStudent → KILLED
        return studentRepository.save(studentDTO.toStudent());
52
    }
53
54
    @Operation(summary = "Update a single student")
55
    @PreAuthorize("hasRole('ROLE_ADMIN')")
56
    @PutMapping("")
57
    public Student updateStudent(@Parameter(name = "id") @RequestParam Long id,
58
                                 @Parameter(name = "student") @RequestBody StudentDTO studentDTO) {
59
        Student student = studentRepository.findById(id)
60 1 1. lambda$updateStudent$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$updateStudent$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Student.class, id));
61
62 1 1. updateStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setLastName → KILLED
        student.setLastName(studentDTO.getLastName());
63 1 1. updateStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setFirstMiddleName → KILLED
        student.setFirstMiddleName(studentDTO.getFirstMiddleName());
64 1 1. updateStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setEmail → KILLED
        student.setEmail(studentDTO.getEmail());
65 1 1. updateStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setPerm → KILLED
        student.setPerm(studentDTO.getPerm());
66 1 1. updateStudent : removed call to edu/ucsb/cs156/happiercows/entities/Student::setCourseId → KILLED
        student.setCourseId(studentDTO.getCourseId());
67
68 1 1. updateStudent : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::updateStudent → KILLED
        return studentRepository.save(student);
69
    }
70
71
    @Operation(summary = "Delete a student")
72
    @PreAuthorize("hasRole('ROLE_ADMIN')")
73
    @DeleteMapping("")
74
    public Object deleteStudent(@Parameter(name = "id") @RequestParam Long id) {
75
        Student student = studentRepository.findById(id)
76 1 1. lambda$deleteStudent$2 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$deleteStudent$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Student.class, id));
77
78 1 1. deleteStudent : removed call to edu/ucsb/cs156/happiercows/repositories/StudentRepository::delete → KILLED
        studentRepository.delete(student);
79 1 1. deleteStudent : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::deleteStudent → KILLED
        return genericMessage("Student with id %d deleted".formatted(id));
80
    }
81
}
82
       

Mutations

34

1.1
Location : allStudents
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:allStudents__user_logged_in()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/StudentController::allStudents → KILLED

43

1.1
Location : lambda$getStudentById$0
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:getStudentById__admin_logged_in_not_found()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$getStudentById$0 → KILLED

44

1.1
Location : getStudentById
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:getStudentById__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::getStudentById → KILLED

51

1.1
Location : postStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:postStudent__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::postStudent → KILLED

60

1.1
Location : lambda$updateStudent$1
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in_not_found()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$updateStudent$1 → KILLED

62

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/entities/Student::setLastName → KILLED

63

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/entities/Student::setFirstMiddleName → KILLED

64

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/entities/Student::setEmail → KILLED

65

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/entities/Student::setPerm → KILLED

66

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/entities/Student::setCourseId → KILLED

68

1.1
Location : updateStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:updateStudent__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::updateStudent → KILLED

76

1.1
Location : lambda$deleteStudent$2
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:deleteStudent__admin_logged_in_not_found()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$deleteStudent$2 → KILLED

78

1.1
Location : deleteStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:deleteStudent__admin_logged_in()]
removed call to edu/ucsb/cs156/happiercows/repositories/StudentRepository::delete → KILLED

79

1.1
Location : deleteStudent
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:deleteStudent__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::deleteStudent → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0