RecommendationRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.RecommendationRequest;
4
import edu.ucsb.cs156.example.entities.UCSBDate;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository;
7
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
13
import com.fasterxml.jackson.core.JsonProcessingException;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.format.annotation.DateTimeFormat;
17
import org.springframework.security.access.prepost.PreAuthorize;
18
import org.springframework.web.bind.annotation.DeleteMapping;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PostMapping;
21
import org.springframework.web.bind.annotation.PutMapping;
22
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.RestController;
26
27
import jakarta.validation.Valid;
28
29
import java.time.LocalDateTime;
30
@Tag(name = "RecommendationRequest")
31
@RequestMapping("/api/recommendationrequest")
32
@RestController
33
@Slf4j
34
public class RecommendationRequestController extends ApiController {
35
    @Autowired
36
    RecommendationRequestRepository recommendationRequestRepository;
37
38
    // GET ALL 
39
    @Operation(summary= "List all recommendation requests")
40
    @PreAuthorize("hasRole('ROLE_USER')")
41
    @GetMapping("/all")
42
    public Iterable<RecommendationRequest> allRecommendationRequest() {
43
        Iterable<RecommendationRequest> dates = recommendationRequestRepository.findAll();
44 1 1. allRecommendationRequest : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequest → KILLED
        return dates;
45
    }
46
47
    // POST
48
    @Operation(summary= "Create a new recommendation request")
49
    @PreAuthorize("hasRole('ROLE_ADMIN')")
50
    @PostMapping("/post")
51
    public RecommendationRequest postRecommendationRequest(
52
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
53
            @Parameter(name="professorEmail") @RequestParam String professorEmail,
54
            @Parameter(name="explanation") @RequestParam String explanation,
55
            @Parameter(name="dateRequested", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested,
56
            @Parameter(name="dateNeeded", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)")  @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded,
57
            @Parameter(name="done") @RequestParam Boolean done)
58
            
59
            
60
            throws JsonProcessingException {
61
62
63
        log.info("localDateTime={}", dateRequested);
64
65
        RecommendationRequest recommendationRequest = new RecommendationRequest();
66 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(requesterEmail);
67 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(professorEmail);
68 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(explanation);
69 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(dateRequested);
70 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(dateNeeded);
71 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(done);
72
73
        RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest);
74
75 1 1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED
        return savedRecommendationRequest;
76
    }
77
78
    // GET SINGLE RECORD
79
    @Operation(summary= "Get a recommendation request")
80
    @PreAuthorize("hasRole('ROLE_USER')")
81
    @GetMapping("")
82
    public RecommendationRequest getById(
83
            @Parameter(name="id") @RequestParam Long id) {
84
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
85 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
86
87 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED
        return recommendationRequest;
88
    }
89
90
    // UPDATE SINGLE 
91
    @Operation(summary = "Update a single request")
92
    @PreAuthorize("hasRole('ROLE_ADMIN')")
93
    @PutMapping("")
94
    public RecommendationRequest recommendationRequest(
95
            @Parameter(name = "id") @RequestParam Long id,
96
            @RequestBody @Valid RecommendationRequest incoming) {
97
98
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
99 1 1. lambda$recommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$recommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
100
101 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
                recommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
102 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
                recommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
103 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
                recommendationRequest.setExplanation(incoming.getExplanation());
104 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
                recommendationRequest.setDateRequested(incoming.getDateRequested());
105 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
                recommendationRequest.setDateNeeded(incoming.getDateNeeded());
106 1 1. recommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
                recommendationRequest.setDone(incoming.getDone());
107
108
        recommendationRequestRepository.save(recommendationRequest);
109
110 1 1. recommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::recommendationRequest → KILLED
        return recommendationRequest;
111
    }
112
113
    @Operation(summary = "Delete a RecommendationRequest")
114
    @PreAuthorize("hasRole('ROLE_ADMIN')")
115
    @DeleteMapping("")
116
    public Object deleteRecommendationRequest(
117
            @Parameter(name = "id") @RequestParam Long id) {
118
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
119 1 1. lambda$deleteRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
120
121 1 1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED
        recommendationRequestRepository.delete(recommendationRequest);
122 1 1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED
        return genericMessage("Recommendation Request with id %s deleted".formatted(id));
123
    }
124
}

Mutations

44

1.1
Location : allRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:logged_in_user_can_get_all_recommendationrequests()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequest → KILLED

66

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

67

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

68

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

69

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

70

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

71

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

75

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED

85

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED

87

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED

99

1.1
Location : lambda$recommendationRequest$1
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_cannot_edit_recommendationrequest_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$recommendationRequest$1 → KILLED

101

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

102

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

103

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

104

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

105

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

106

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

110

1.1
Location : recommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::recommendationRequest → KILLED

119

1.1
Location : lambda$deleteRecommendationRequest$2
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_tries_to_delete_non_existant_recommendationrequest_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$2 → KILLED

121

1.1
Location : deleteRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_delete_a_request()]
removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED

122

1.1
Location : deleteRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_delete_a_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0