HelpRequestController.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
@Tag(name = "HelpRequest")
26
@RequestMapping("/api/helprequest")
27
@RestController
28
@Slf4j
29
public class HelpRequestController extends ApiController {
30
31
  @Autowired HelpRequestRepository helpRequestRepository;
32
33
  /**
34
   * List all UCSB dates
35
   *
36
   * @return an iterable of UCSBDate
37
   */
38
  @Operation(summary = "List all help requests")
39
  @PreAuthorize("hasRole('ROLE_USER')")
40
  @GetMapping("/all")
41
  public Iterable<HelpRequest> allHelpRequests() {
42
    Iterable<HelpRequest> helprequest = helpRequestRepository.findAll();
43 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
    return helprequest;
44
  }
45
46
  /**
47
   * Get a single request by id
48
   *
49
   * @param id the id of the request
50
   * @return a HelpRequest
51
   */
52
  @Operation(summary = "Get a single help request")
53
  @PreAuthorize("hasRole('ROLE_USER')")
54
  @GetMapping("")
55
  public HelpRequest getById(@Parameter(name = "id") @RequestParam Long id) {
56
    HelpRequest helpRequest =
57
        helpRequestRepository
58
            .findById(id)
59 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));
60
61 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
    return helpRequest;
62
  }
63
64
  /**
65
   * Create a new help request
66
   *
67
   * @param requesterEmail email of the student making the request
68
   * @param teamId team identifier
69
   * @param tableOrBreakoutRoom the content of the request
70
   * @param solved could be "true" or "false"
71
   * @param explanation optional additional context
72
   * @param requestTime get time
73
   */
74
  @Operation(summary = "Create a new help request")
75
  @PreAuthorize("hasRole('ROLE_ADMIN')")
76
  @PostMapping("/post")
77
  public HelpRequest postHelpRequest(
78
      @Parameter(name = "requesterEmail") @RequestParam String requesterEmail,
79
      @Parameter(name = "teamId") @RequestParam String teamId,
80
      @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
81
      @Parameter(name = "solved") @RequestParam boolean solved,
82
      @Parameter(name = "explanation") @RequestParam String explanation,
83
      @Parameter(
84
              name = "requestTime",
85
              description =
86
                  "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)")
87
          @RequestParam("requestTime")
88
          @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
89
          LocalDateTime requestTime)
90
      throws JsonProcessingException {
91
92
    // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
93
    // See: https://www.baeldung.com/spring-date-parameters
94
95
    log.info("requestTime={}", requestTime);
96
97
    HelpRequest helpRequest = new HelpRequest();
98 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
    helpRequest.setRequesterEmail(requesterEmail);
99 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
    helpRequest.setTeamId(teamId);
100 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
    helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
101 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
    helpRequest.setRequestTime(requestTime);
102 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
    helpRequest.setExplanation(explanation);
103 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
    helpRequest.setSolved(solved);
104
105
    HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest);
106
107 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED
    return savedHelpRequest;
108
  }
109
110
  /**
111
   * Delete a HelpRequest
112
   *
113
   * @param id the id of the help request to delete
114
   * @return a message indicating the help request was deleted
115
   */
116
  @Operation(summary = "Delete a HelpRequest")
117
  @PreAuthorize("hasRole('ROLE_ADMIN')")
118
  @DeleteMapping("")
119
  public Object deleteHelpRequest(@Parameter(name = "id") @RequestParam Long id) {
120
    HelpRequest helpRequest =
121
        helpRequestRepository
122
            .findById(id)
123 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));
124
125 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
    helpRequestRepository.delete(helpRequest);
126 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));
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/HelpRequestController::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/HelpRequestController::updateHelpRequest → KILLED
    return helpRequest;
157
  }
158
}

Mutations

43

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_requests()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED

59

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:get_by_id_when_not_found()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED

61

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

98

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

99

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

100

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

101

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

102

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

103

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

107

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

123

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:delete_not_found_returns_404()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED

125

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_help_request()]
removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED

126

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_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED

145

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

147

1.1
Location : updateHelpRequest
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[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.HelpRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestControllerTests]/[method:admin_can_edit_an_existing_help_request()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0