DriverAvailabilityController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import edu.ucsb.cs156.gauchoride.entities.DriverAvailability;
4
import edu.ucsb.cs156.gauchoride.entities.Ride;
5
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.gauchoride.repositories.DriverAvailabilityRepository;
7
8
import io.swagger.v3.oas.annotations.tags.Tag;
9
import io.swagger.v3.oas.annotations.Operation;
10
import io.swagger.v3.oas.annotations.Parameter;
11
12
import java.lang.Iterable;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.security.access.prepost.PreAuthorize;
15
import org.springframework.security.core.authority.SimpleGrantedAuthority;
16
import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import javax.validation.Valid;
27
28
29
@Tag(name = "DriverAvailability Request")
30
@RequestMapping("/api/driverAvailability")
31
@RestController
32
33
public class DriverAvailabilityController extends ApiController {
34
35
    @Autowired
36
    DriverAvailabilityRepository driverAvailabilityRepository;
37
38
    @Operation(summary = "List all availabilities if admin")
39
    @PreAuthorize("hasRole('ROLE_ADMIN')")
40
    @GetMapping("admin/all")
41
    public Iterable<DriverAvailability> allDriverAvailabilitys() {
42 1 1. allDriverAvailabilitys : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilitys → KILLED
        return driverAvailabilityRepository.findAll();
43
    }
44
45
    @Operation(summary = "Get a single availability by id, if user is an admin")
46
    @PreAuthorize("hasRole('ROLE_ADMIN')")
47
    @GetMapping("admin")
48
    public DriverAvailability getByIdAdmin(
49
            @Parameter(name="id", description = "long, Id of the DriverAvailability to get", 
50
            required = true)  
51
            @RequestParam Long id) {
52
        DriverAvailability driverAvailability;
53
        driverAvailability = driverAvailabilityRepository.findById(id)
54 1 1. lambda$getByIdAdmin$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getByIdAdmin$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));;
55 1 1. getByIdAdmin : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getByIdAdmin → KILLED
        return driverAvailability;
56
    }
57
58
59
    @Operation(summary = "Update a driver Availability, only user's if not Driver/Admin")
60
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')")
61
    @PutMapping("")
62
    public DriverAvailability updateDriverAvailability(
63
            @Parameter(name="id", description="long, Id of the DriverAvailability to be edited", 
64
            required = true)
65
            @RequestParam Long id,
66
            @RequestBody @Valid DriverAvailability incoming) {
67
68
        DriverAvailability driverAvailability;
69
70 1 1. updateDriverAvailability : negated conditional → KILLED
        if (getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_ADMIN")) ||
71 1 1. updateDriverAvailability : negated conditional → KILLED
        getCurrentUser().getRoles().contains(new SimpleGrantedAuthority("ROLE_DRIVER"))) {
72
            driverAvailability = driverAvailabilityRepository.findById(id)
73 1 1. lambda$updateDriverAvailability$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updateDriverAvailability$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));}
74
        else{
75
            driverAvailability = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId())
76 1 1. lambda$updateDriverAvailability$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updateDriverAvailability$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
77
        }
78
    
79
    
80
81 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        driverAvailability.setDay(incoming.getDay());
82 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        driverAvailability.setStartTime(incoming.getStartTime());
83 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        driverAvailability.setEndTime(incoming.getEndTime());
84 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        driverAvailability.setNotes(incoming.getNotes());
85
86
        driverAvailabilityRepository.save(driverAvailability);
87 1 1. updateDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::updateDriverAvailability → KILLED
        return driverAvailability;
88
    }
89
90
  
91
    @Operation(summary = "Create a new Driver Availability")
92
    @PreAuthorize("hasRole('ROLE_DRIVER')")
93
    @PostMapping("/post")
94
    public DriverAvailability postDriverAvailability(
95
96
        @Parameter(name="day", description="String, Day of the week the driver is available and allows Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday", 
97
                    example="Tuesday", required = true) 
98
        @RequestParam String day,
99
100
        @Parameter(name="startTime", description="String, Time the driver starts drivingHH:MM(A/P)M", example="12:30AM", required = true)
101
        @RequestParam String startTime,
102
103
        @Parameter(name="endTime", description="String, Time the driver ends driving HH:MM(A/P)M", example="12:30AM", required = true)
104
        @RequestParam String endTime,
105
106
        @Parameter(name="notes", description="String, Extra information", example="We have two people riding", required = true)
107
        @RequestParam String notes
108
        )
109
        {
110
111
        DriverAvailability driverAvailability = new DriverAvailability();
112
        
113 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED
        driverAvailability.setDriverId(getCurrentUser().getUser().getId());
114 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        driverAvailability.setDay(day);
115 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        driverAvailability.setStartTime(startTime);
116 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        driverAvailability.setEndTime(endTime);
117 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        driverAvailability.setNotes(notes);
118
119
        DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability);
120
121 1 1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED
        return savedDriverAvailability;
122
    }
123
124
125
    @Operation(summary = "Delete an availability if owned by current user")
126
    @PreAuthorize("hasRole('ROLE_USER')")
127
    @DeleteMapping("")
128
    public Object deleteDriverAvailability(
129
        @Parameter(name="id", description="long, Id of the DriverAvailability to be deleted", 
130
        required = true) @RequestParam long id) {
131
132
        DriverAvailability availability;
133
134
        availability = driverAvailabilityRepository.findByIdAndDriverId(id, getCurrentUser().getUser().getId())
135 1 1. lambda$deleteDriverAvailability$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deleteDriverAvailability$3 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
136 1 1. deleteDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED
        driverAvailabilityRepository.delete(availability);
137
        
138 1 1. deleteDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::deleteDriverAvailability → KILLED
        return genericMessage("DriverAvailability with id %s deleted".formatted(id));
139
    }
140
}
141

Mutations

42

1.1
Location : allDriverAvailabilitys
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:logged_in_admin_can_get_all_driver_availability()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilitys → KILLED

54

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

55

1.1
Location : getByIdAdmin
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:admingetbyidworks()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getByIdAdmin → KILLED

70

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

71

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

73

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

76

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

81

1.1
Location : updateDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:test_that_logged_in_driver_can_update_when_the_availability_exists()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED

82

1.1
Location : updateDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:test_that_logged_in_driver_can_update_when_the_availability_exists()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED

83

1.1
Location : updateDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:test_that_logged_in_driver_can_update_when_the_availability_exists()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED

84

1.1
Location : updateDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:test_that_logged_in_driver_can_update_when_the_availability_exists()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED

87

1.1
Location : updateDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:test_that_logged_in_driver_can_update_when_the_availability_exists()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::updateDriverAvailability → KILLED

113

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED

114

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED

115

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED

116

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED

117

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED

121

1.1
Location : postDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:a_driver_user_can_post_a_new_driver_availability()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED

135

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

136

1.1
Location : deleteDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:user_can_delete_availability()]
removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED

138

1.1
Location : deleteDriverAvailability
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[method:user_can_delete_availability()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::deleteDriverAvailability → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3