StudentController.java

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
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.happiercows.controllers.StudentControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.StudentControllerTests]/[method:admin_users_cannot_get_by_id_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/StudentController::lambda$getById$0 → KILLED

41

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

52

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

62

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

64

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

65

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

80

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

83

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

84

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

85

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

86

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

87

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

89

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

Active mutators

Tests examined


Report generated by PIT 1.7.3