RideRequestController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
6
import edu.ucsb.cs156.gauchoride.entities.RideRequest;
7
import edu.ucsb.cs156.gauchoride.repositories.RideRequestRepository;
8
9
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
10
11
import org.springframework.security.access.AccessDeniedException;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.http.ResponseEntity;
14
import org.springframework.security.access.prepost.PreAuthorize;
15
import org.springframework.web.bind.annotation.DeleteMapping;
16
import org.springframework.web.bind.annotation.PutMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PathVariable;
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
import io.swagger.annotations.Api;
26
import io.swagger.annotations.ApiOperation;
27
import io.swagger.annotations.ApiParam;
28
29
import javax.validation.Valid;
30
31
@Api(description = "Ride request information")
32
@RequestMapping("/api/riderequests")
33
@RestController
34
public class RideRequestController extends ApiController {
35
    @Autowired
36
    RideRequestRepository rideRequestRepository;
37
38
    @Autowired
39
    ObjectMapper mapper;
40
41
    @ApiOperation(value = "Delete a ride request (admin)")
42
    @PreAuthorize("hasRole('ROLE_ADMIN')")
43
    @DeleteMapping("/delete")
44
    public Object deleteRideRequest_Admin(
45
        @ApiParam("id") @RequestParam Long id) {
46
            RideRequest rideRequest = rideRequestRepository.findById(id)
47 1 1. lambda$deleteRideRequest_Admin$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Admin$0 → KILLED
        .orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id));
48
49 1 1. deleteRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED
        rideRequestRepository.delete(rideRequest);
50
51 1 1. deleteRideRequest_Admin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Admin → KILLED
        return genericMessage("Ride request with id %s deleted".formatted(id));
52
    }
53
54
    @ApiOperation(value = "Delete a ride request (rider)")
55
    @PreAuthorize("hasRole('ROLE_RIDER')")
56
    @DeleteMapping("/delete/rider")
57
    public Object deleteRideRequest_Rider(
58
        @ApiParam("id") @RequestParam Long id) {
59
            RideRequest rideRequest = rideRequestRepository.findById(id)
60 1 1. lambda$deleteRideRequest_Rider$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Rider$1 → KILLED
        .orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id));
61
62
        Long userId = getCurrentUser().getUser().getId();
63 1 1. deleteRideRequest_Rider : negated conditional → KILLED
        if(userId == rideRequest.getRiderId()){
64 1 1. deleteRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED
            rideRequestRepository.delete(rideRequest);
65 1 1. deleteRideRequest_Rider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Rider → KILLED
            return genericMessage("Ride request with id %s deleted".formatted(id));
66
        }else{
67
            throw new AccessDeniedException("403 returned"); 
68
        }
69
    }
70
71
    @ApiOperation(value = "Update a ride request (admin)")
72
    @PreAuthorize("hasRole('ROLE_ADMIN')")
73
    @PutMapping("/put")
74
    public RideRequest updateRideRequest_Admin(
75
            @ApiParam("id") @RequestParam Long id,
76
            @RequestBody @Valid RideRequest incoming) {
77
78
        RideRequest rideRequest = rideRequestRepository.findById(id)
79 1 1. lambda$updateRideRequest_Admin$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Admin$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id));
80
81 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED
        rideRequest.setDay(incoming.getDay());
82 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED
        rideRequest.setCourse(incoming.getCourse());
83 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED
        rideRequest.setStartTime(incoming.getStartTime());
84 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED
        rideRequest.setStopTime(incoming.getStopTime());
85 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED
        rideRequest.setBuilding(incoming.getBuilding());
86 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED
        rideRequest.setRoom(incoming.getRoom());
87 1 1. updateRideRequest_Admin : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED
        rideRequest.setPickupLocation(incoming.getPickupLocation());
88
89
        rideRequestRepository.save(rideRequest);
90
91 1 1. updateRideRequest_Admin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Admin → KILLED
        return rideRequest;
92
    }
93
94
	@ApiOperation(value = "Update a ride request (rider)")
95
    @PreAuthorize("hasRole('ROLE_RIDER')")
96
    @PutMapping("/put/rider")
97
    public RideRequest updateRideRequest_Rider(
98
        @ApiParam("id") @RequestParam Long id,
99
        @RequestBody @Valid RideRequest incoming) {
100
101
		Long userId = getCurrentUser().getUser().getId();
102
103
        RideRequest rideRequest = rideRequestRepository.findById(id)
104 1 1. lambda$updateRideRequest_Rider$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Rider$3 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RideRequest.class, id));
105
106 1 1. updateRideRequest_Rider : negated conditional → KILLED
		if(userId == rideRequest.getRiderId()){
107 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED
			rideRequest.setDay(incoming.getDay());
108 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED
			rideRequest.setCourse(incoming.getCourse());
109 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED
			rideRequest.setStartTime(incoming.getStartTime());
110 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED
			rideRequest.setStopTime(incoming.getStopTime());
111 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED
			rideRequest.setBuilding(incoming.getBuilding());
112 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED
			rideRequest.setRoom(incoming.getRoom());
113 1 1. updateRideRequest_Rider : removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED
			rideRequest.setPickupLocation(incoming.getPickupLocation());
114
115
			rideRequestRepository.save(rideRequest);
116
117 1 1. updateRideRequest_Rider : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Rider → KILLED
			return rideRequest;
118
		}else{
119
			throw new AccessDeniedException("403 returned"); 
120
		}
121
    }
122
}

Mutations

47

1.1
Location : lambda$deleteRideRequest_Admin$0
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_delete_non_existant()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Admin$0 → KILLED

49

1.1
Location : deleteRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_delete()]
removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED

51

1.1
Location : deleteRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_delete()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Admin → KILLED

60

1.1
Location : lambda$deleteRideRequest_Rider$1
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_delete_non_existant()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$deleteRideRequest_Rider$1 → KILLED

63

1.1
Location : deleteRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_delete_unowned_request()]
negated conditional → KILLED

64

1.1
Location : deleteRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_delete()]
removed call to edu/ucsb/cs156/gauchoride/repositories/RideRequestRepository::delete → KILLED

65

1.1
Location : deleteRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_delete()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::deleteRideRequest_Rider → KILLED

79

1.1
Location : lambda$updateRideRequest_Admin$2
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Admin$2 → KILLED

81

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED

82

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED

83

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED

84

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED

85

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED

86

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED

87

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED

91

1.1
Location : updateRideRequest_Admin
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:admin_edit()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Admin → KILLED

104

1.1
Location : lambda$updateRideRequest_Rider$3
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::lambda$updateRideRequest_Rider$3 → KILLED

106

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit_unowned()]
negated conditional → KILLED

107

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setDay → KILLED

108

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setCourse → KILLED

109

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStartTime → KILLED

110

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setStopTime → KILLED

111

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setBuilding → KILLED

112

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setRoom → KILLED

113

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
removed call to edu/ucsb/cs156/gauchoride/entities/RideRequest::setPickupLocation → KILLED

117

1.1
Location : updateRideRequest_Rider
Killed by : edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.RideRequestControllerTests]/[method:rider_edit()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RideRequestController::updateRideRequest_Rider → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3