HelpRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.HelpRequest;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.HelpRequestRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import com.fasterxml.jackson.core.JsonProcessingException;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.format.annotation.DateTimeFormat;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import jakarta.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
@Tag(name = "HelpRequest")
31
@RequestMapping("/api/helprequest")
32
@RestController
33
@Slf4j
34
35
public class HelpRequestController extends ApiController {
36
37
  @Autowired
38
  HelpRequestRepository helpRequestRepository;
39
40
  /**
41
     * List all HelpRequests 
42
     * 
43
     * @return an iterable of HelpRequest
44
     */
45
    @Operation(summary= "List all HelpRequests")
46
    @PreAuthorize("hasRole('ROLE_USER')")
47
    @GetMapping("/all")
48
    public Iterable<HelpRequest> allHelpRequests() {
49
        Iterable<HelpRequest> requests = helpRequestRepository.findAll();
50 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
        return requests;
51
    }
52
53
    /**
54
     * Post a new HelpRequest
55
     * 
56
     * @param requesterEmail
57
     * @param teamId
58
     * @param tableOrBreakoutRoom
59
     * @param requestTime
60
     * @param explanation
61
     * @param solved
62
     * @return the new HelpRequest
63
     */
64
    @Operation(summary= "Create a new HelpRequest")
65
    @PreAuthorize("hasRole('ROLE_ADMIN')")
66
    @PostMapping("/post")
67
    public HelpRequest postMenuItemReview(
68
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
69
            @Parameter(name="teamId") @RequestParam String teamId,
70
            @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
71
            @Parameter(name="requestTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime,
72
            @Parameter(name="explanation") @RequestParam String explanation,
73
            @Parameter(name="solved") @RequestParam boolean solved)
74
            throws JsonProcessingException {
75
76
              // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
77
              // See: https://www.baeldung.com/spring-date-parameters
78
      
79
              log.info("requestTime={}", requestTime);
80
      
81
              HelpRequest helpRequest = new HelpRequest();
82 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
              helpRequest.setRequesterEmail(requesterEmail);
83 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
              helpRequest.setTeamId(teamId);
84 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
              helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
85 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
              helpRequest.setRequestTime(requestTime);
86 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
              helpRequest.setExplanation(explanation);
87 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
              helpRequest.setSolved(solved);
88
              HelpRequest savedMenuItemReview = helpRequestRepository.save(helpRequest);
89 1 1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postMenuItemReview → KILLED
              return savedMenuItemReview;
90
          }
91
          
92
    
93
           /** Get a single request by id
94
           * 
95
           * @param id the id of the review
96
           * @return a HelpRequest object
97
           */
98
           @Operation(summary= "Get a single request")
99
           @PreAuthorize("hasRole('ROLE_USER')")
100
           @GetMapping("")
101
           public HelpRequest getById(
102
                   @Parameter(name="id") @RequestParam Long id) {
103
               HelpRequest helpRequest = helpRequestRepository.findById(id)
104 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED
                       .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
105
106 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
               return helpRequest;
107
           }
108
                
109
             /**
110
            * Delete a HelpRequest
111
            * 
112
            * @param id         the id of the review to delete
113
            * @return           a message indicating the review was deleted
114
             */
115
             @Operation(summary= "Delete a HelpRequest")
116
             @PreAuthorize("hasRole('ROLE_ADMIN')")
117
             @DeleteMapping("")
118
             public Object deleteHelpRequest(
119
                   @Parameter(name="id") @RequestParam Long id) {
120
               HelpRequest helpRequest = helpRequestRepository.findById(id)
121 1 1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED
                       .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
122
                
123 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
               helpRequestRepository.delete(helpRequest);
124 1 1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED
               return genericMessage("HelpRequest with id %s deleted".formatted(id));
125
             }
126
                  
127
                
128
             /**
129
             * Update a single review
130
             * 
131
             * @param id            id of the review to update
132
             * @param incoming      the new review
133
             * @return the updated review object
134
             */
135
             @Operation(summary= "Update a single request")
136
             @PreAuthorize("hasRole('ROLE_ADMIN')")
137
             @PutMapping("")
138
             public HelpRequest updateMenuItemReview(
139
               @Parameter(name="id") @RequestParam Long id,
140
               @RequestBody @Valid HelpRequest incoming) {
141
142
               HelpRequest helpRequest = helpRequestRepository.findById(id)
143 1 1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateMenuItemReview$2 → KILLED
                       .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
144
145 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
                  helpRequest.setRequesterEmail(incoming.getRequesterEmail());
146 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
                  helpRequest.setTeamId(incoming.getTeamId());
147 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
                  helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
148 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
                  helpRequest.setRequestTime(incoming.getRequestTime());
149 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
                  helpRequest.setExplanation(incoming.getExplanation());
150 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
                  helpRequest.setSolved(incoming.getSolved());
151
152
               helpRequestRepository.save(helpRequest);
153 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateMenuItemReview → KILLED
               return helpRequest;
154
     }
155
}

Mutations

50

1.1
Location : allHelpRequests
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:logged_in_user_can_get_all_helprequests()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED

82

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

83

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

84

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

85

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

86

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

87

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

89

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_user_can_post_a_new_helprequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postMenuItemReview → KILLED

104

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

106

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

121

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

123

1.1
Location : deleteHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_delete_a_help_request()]
removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED

124

1.1
Location : deleteHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_delete_a_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED

143

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

145

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

146

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

147

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

148

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

149

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

150

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

153

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_update_existing_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateMenuItemReview → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0