DriverAvailabilityController.java

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

Mutations

40

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

52

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

53

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

78

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

79

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

80

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

81

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

82

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

86

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

99

1.1
Location : lambda$deleteDriverAvailability$1
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$1 → KILLED

100

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

102

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

111

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

Active mutators

Tests examined


Report generated by PIT 1.7.3