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

Mutations

66

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

104

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

105

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

106

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

107

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED

108

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

109

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_helpreqequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

113

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

129

1.1
Location : lambda$getById$0
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$0 → KILLED

131

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

150

1.1
Location : lambda$updateHelpRequest$1
Killed by : edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HelpRequestsControllerTests]/[method:admin_cannot_edit_helprequest_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$updateHelpRequest$1 → 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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED

153

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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED

154

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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED

155

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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → 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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED

157

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_helprequest()]
removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED

161

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

177

1.1
Location : lambda$deleteHelpRequest$2
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_helprequest_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$2 → KILLED

179

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

180

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

Active mutators

Tests examined


Report generated by PIT 1.17.0