HelpRequestsController.java

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

Mutations

43

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

81

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

82

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

83

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

84

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

85

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

86

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

89

1.1
Location : postHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[method:an_admin_user_can_post_a_new_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED

105

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

107

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

108

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

124

1.1
Location : lambda$getById$1
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[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/HelpRequestsController::lambda$getById$1 → KILLED

126

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[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/HelpRequestsController::getById → KILLED

145

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

147

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

148

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

149

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

150

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

151

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

152

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

156

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[method:admin_can_edit_an_existing_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0