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
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
import io.swagger.v3.oas.annotations.tags.Tag;
9
import jakarta.validation.Valid;
10
import java.time.LocalDateTime;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.format.annotation.DateTimeFormat;
14
import org.springframework.security.access.prepost.PreAuthorize;
15
import org.springframework.web.bind.annotation.DeleteMapping;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.PostMapping;
18
import org.springframework.web.bind.annotation.PutMapping;
19
import org.springframework.web.bind.annotation.RequestBody;
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
24
/** This is a REST controller for HelpRequest */
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 HelpRequests
35
   *
36
   * @return an iterable of HelpRequests
37
   */
38
  @Operation(summary = "List all help requests")
39
  @PreAuthorize("hasRole('ROLE_USER')")
40
  @GetMapping("/all")
41
  public Iterable<HelpRequest> allHelpRequests() {
42 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
    return helpRequestRepository.findAll();
43
  }
44
45
  /**
46
   * Get a single HelpRequest by id
47
   *
48
   * @param id the id of the HelpRequest
49
   * @return a HelpRequest
50
   */
51
  @Operation(summary = "Get a single help request")
52
  @PreAuthorize("hasRole('ROLE_USER')")
53
  @GetMapping("")
54
  public HelpRequest getById(@Parameter(name = "id") @RequestParam Long id) {
55
    HelpRequest helpRequest =
56
        helpRequestRepository
57
            .findById(id)
58 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));
59
60 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
    return helpRequest;
61
  }
62
63
  /**
64
   * Update a single HelpRequest
65
   *
66
   * @param id the id of the HelpRequest
67
   * @param incoming the new HelpRequest values
68
   * @return the updated HelpRequest
69
   */
70
  @Operation(summary = "Update a single help request")
71
  @PreAuthorize("hasRole('ROLE_ADMIN')")
72
  @PutMapping("")
73
  public HelpRequest updateHelpRequest(
74
      @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid HelpRequest incoming) {
75
    HelpRequest helpRequest =
76
        helpRequestRepository
77
            .findById(id)
78 1 1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id));
79
80 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
    helpRequest.setRequesterEmail(incoming.getRequesterEmail());
81 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
    helpRequest.setTeamId(incoming.getTeamId());
82 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
    helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom());
83 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
    helpRequest.setRequestTime(incoming.getRequestTime());
84 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
    helpRequest.setExplanation(incoming.getExplanation());
85 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
    helpRequest.setSolved(incoming.getSolved());
86
87
    helpRequestRepository.save(helpRequest);
88
89 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED
    return helpRequest;
90
  }
91
92
  /**
93
   * Delete a HelpRequest
94
   *
95
   * @param id the id of the HelpRequest
96
   * @return a message that the HelpRequest was deleted
97
   */
98
  @Operation(summary = "Delete a help request")
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$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$2 → 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
109 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));
110
  }
111
112
  /**
113
   * Create a new HelpRequest
114
   *
115
   * @param requesterEmail email of the person requesting help
116
   * @param teamId team id of the person requesting help
117
   * @param tableOrBreakoutRoom table or breakout room where help is needed
118
   * @param requestTime time when help was requested
119
   * @param explanation explanation of the request
120
   * @param solved whether the request has been solved
121
   * @return the saved HelpRequest
122
   */
123
  @Operation(summary = "Create a new help request")
124
  @PreAuthorize("hasRole('ROLE_ADMIN')")
125
  @PostMapping("/post")
126
  public HelpRequest postHelpRequest(
127
      @Parameter(name = "requesterEmail") @RequestParam String requesterEmail,
128
      @Parameter(name = "teamId") @RequestParam String teamId,
129
      @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
130
      @Parameter(
131
              name = "requestTime",
132
              description =
133
                  "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)")
134
          @RequestParam("requestTime")
135
          @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
136
          LocalDateTime requestTime,
137
      @Parameter(name = "explanation") @RequestParam String explanation,
138
      @Parameter(name = "solved") @RequestParam boolean solved) {
139
140
    HelpRequest helpRequest = new HelpRequest();
141 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
    helpRequest.setRequesterEmail(requesterEmail);
142 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
    helpRequest.setTeamId(teamId);
143 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
    helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
144 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
    helpRequest.setRequestTime(requestTime);
145 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
    helpRequest.setExplanation(explanation);
146 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
    helpRequest.setSolved(solved);
147
148 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED
    return helpRequestRepository.save(helpRequest);
149
  }
150
}

Mutations

42

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

58

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: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/HelpRequestController::lambda$getById$0 → KILLED

60

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

78

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

80

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

81

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

82

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

83

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

84

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

85

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

89

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

105

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

107

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

109

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

141

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

142

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

143

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

144

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

145

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

146

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

148

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

Active mutators

Tests examined


Report generated by PIT 1.17.0