RequestTypesController.java

1
package edu.ucsb.cs156.rec.controllers;
2
3
import edu.ucsb.cs156.rec.entities.RequestType;
4
import edu.ucsb.cs156.rec.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.rec.repositories.RequestTypeRepository;
6
import edu.ucsb.cs156.rec.services.RequestTypeService;
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 lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestParam;
18
import org.springframework.web.bind.annotation.RestController;
19
20
/**
21
 * This is a REST controller for Request Types
22
 */
23
24
@Tag(name = "RequestTypes")
25
@RequestMapping("/api/requesttypes")
26
@RestController
27
@Slf4j
28
public class RequestTypesController extends ApiController {
29
30
    @Autowired
31
    RequestTypeRepository requestTypeRepository;
32
33
	@Autowired
34
	RequestTypeService requestTypeService;
35
36
    /**
37
     * This method returns a list of all request types.
38
     * @return a list of all request types
39
     */
40
    @Operation(summary = "List all request types")
41
    @PreAuthorize("hasRole('ROLE_USER')")
42
    @GetMapping("/all")
43
    public Iterable<RequestType> allRequestTypes() {
44
        Iterable<RequestType> requestTypes = requestTypeRepository.findAll();
45 1 1. allRequestTypes : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/controllers/RequestTypesController::allRequestTypes → KILLED
        return requestTypes;
46
    }
47
48
    /**
49
     * This method returns a single request type.
50
     * @param id id of the request type to get
51
     * @return a single request type
52
     */
53
    @Operation(summary = "Get a single request type")
54
    @PreAuthorize("hasRole('ROLE_USER')")
55
    @GetMapping("")
56
    public RequestType getById(
57
            @Parameter(name = "id") @RequestParam Long id) {
58
		RequestType requestType = requestTypeRepository.findById(id)
59 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RequestType.class, id));
60
61 1 1. getById : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::getById → KILLED
        return requestType;
62
    }
63
64
    /**
65
     * This method creates a new request type. Accessible only to users with the role "ROLE_ADMIN" or "ROLE_INSTRUCTOR".
66
     * @param requestType description of the request type
67
     * @return the save request type (with it's id field set by the database)
68
     */
69
    @Operation(summary = "Create a new request type")
70
    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTRUCTOR')")
71
    @PostMapping("/post")
72
    public RequestType postRequestType(
73
            @Parameter(name = "requestType") @RequestParam String requestType) {
74
75
        RequestType savingRequestType = new RequestType();
76 1 1. postRequestType : removed call to edu/ucsb/cs156/rec/entities/RequestType::setRequestType → KILLED
        savingRequestType.setRequestType(requestType);
77
78 1 1. postRequestType : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::postRequestType → KILLED
        return requestTypeService.trySave(savingRequestType);
79
    }
80
}

Mutations

45

1.1
Location : allRequestTypes
Killed by : edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests]/[method:logged_in_user_can_get_all_request_types()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/controllers/RequestTypesController::allRequestTypes → KILLED

59

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests]/[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/rec/controllers/RequestTypesController::lambda$getById$0 → KILLED

61

1.1
Location : getById
Killed by : edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::getById → KILLED

76

1.1
Location : postRequestType
Killed by : edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests]/[method:an_instructor_can_post_a_new_request_type()]
removed call to edu/ucsb/cs156/rec/entities/RequestType::setRequestType → KILLED

78

1.1
Location : postRequestType
Killed by : edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RequestTypesControllerTests]/[method:an_instructor_can_post_a_new_request_type()]
replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::postRequestType → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0