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
/** This is a REST controller for HelpRequests */
26
@Tag(name = "HelpRequest")
27
@RequestMapping("/api/helprequest")
28
@RestController
29
@Slf4j
30
public class HelpRequestController extends ApiController {
31
32
  @Autowired HelpRequestRepository helpRequestRepository;
33
34
  /**
35
   * List all help requests
36
   *
37
   * @return an iterable of HelpRequest
38
   */
39
  @Operation(summary = "List all help requests")
40
  @PreAuthorize("hasRole('ROLE_USER')")
41
  @GetMapping("/all")
42
  public Iterable<HelpRequest> allHelpRequests() {
43
    Iterable<HelpRequest> helpRequests = helpRequestRepository.findAll();
44 1 1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED
    return helpRequests;
45
  }
46
47
  /*
48
   * Create a new help request
49
   * String requesterEmail
50
   * String teamId
51
   * String tableOrBreakoutRoom
52
   * LocalDateTime requestTime
53
   * String explanation
54
   * boolean solved
55
   *
56
   * @return the posted HelpRequest
57
   */
58
  @Operation(summary = "Create a new help request")
59
  @PreAuthorize("hasRole('ROLE_ADMIN')")
60
  @PostMapping("/post")
61
  public HelpRequest postHelpRequest(
62
      @Parameter(name = "requesterEmail") @RequestParam String requesterEmail,
63
      @Parameter(name = "teamId") @RequestParam String teamId,
64
      @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom,
65
      @Parameter(
66
              name = "requestTime",
67
              description =
68
                  "in iso format - YYYY-MM-DDTHH:MM:SS, see in https://en.wikipedia.org/wiki/ISO_8601, e.g. 2007-03-01T13:00:00")
69
          @RequestParam("requestTime")
70
          @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
71
          LocalDateTime reqDateTime,
72
      @Parameter(name = "explanation") @RequestParam String explanation,
73
      @Parameter(name = "solved") @RequestParam boolean solved)
74
      throws JsonProcessingException {
75
    HelpRequest helpRequest = new HelpRequest();
76 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
    helpRequest.setRequesterEmail(requesterEmail);
77 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
    helpRequest.setTeamId(teamId);
78 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
    helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom);
79 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
    helpRequest.setRequestTime(reqDateTime);
80 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
    helpRequest.setExplanation(explanation);
81 1 1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
    helpRequest.setSolved(solved);
82
    HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest);
83 1 1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED
    return savedHelpRequest;
84
  }
85
86
  /**
87
   * Get a HelpRequest by id
88
   *
89
   * @param id the id of the HelpRequest
90
   * @return the HelpRequest if it is found
91
   */
92
  @Operation(summary = "Get a help request")
93
  @PreAuthorize("hasRole('ROLE_USER')")
94
  @GetMapping("")
95
  public HelpRequest getById(@Parameter(name = "id") @RequestParam Long id) {
96
97 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED
    return helpRequestRepository
98
        .findById(id)
99 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));
100
  }
101
102
  /**
103
   * Update a HelpRequest by id
104
   *
105
   * @param id the id of the HelpRequest
106
   * @param update the HelpRequest containing the updates
107
   * @return the updated HelpRequest
108
   */
109
  @Operation(summary = "Update a help request")
110
  @PreAuthorize("hasRole('ROLE_ADMIN')")
111
  @PutMapping("")
112
  public HelpRequest updateHelpRequest(
113
      @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid HelpRequest update) {
114
115
    HelpRequest existing =
116
        helpRequestRepository
117
            .findById(id)
118 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));
119
120 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED
    existing.setRequesterEmail(update.getRequesterEmail());
121 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED
    existing.setTeamId(update.getTeamId());
122 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED
    existing.setTableOrBreakoutRoom(update.getTableOrBreakoutRoom());
123 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED
    existing.setRequestTime(update.getRequestTime());
124 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED
    existing.setExplanation(update.getExplanation());
125 1 1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED
    existing.setSolved(update.getSolved());
126
127
    helpRequestRepository.save(existing);
128 1 1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED
    return existing;
129
  }
130
131
  @Operation(summary = "Delete a help request")
132
  @PreAuthorize("hasRole('ROLE_ADMIN')")
133
  @DeleteMapping("")
134
  public Object deleteHelpRequest(@Parameter(name = "id") @RequestParam Long id) {
135
    HelpRequest existing =
136
        helpRequestRepository
137
            .findById(id)
138 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));
139
140 1 1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED
    helpRequestRepository.delete(existing);
141 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));
142
  }
143
}

Mutations

44

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

76

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

77

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

78

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

79

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

80

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

81

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

83

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

97

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

99

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

118

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

120

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

121

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

122

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

123

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

124

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

125

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

128

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

138

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

140

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

141

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

Active mutators

Tests examined


Report generated by PIT 1.17.0