DriverAvailabilityController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import javax.validation.Valid;
4
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.security.access.prepost.PreAuthorize;
8
import org.springframework.web.bind.annotation.DeleteMapping;
9
import org.springframework.web.bind.annotation.GetMapping;
10
import org.springframework.web.bind.annotation.PostMapping;
11
import org.springframework.web.bind.annotation.PutMapping;
12
import org.springframework.web.bind.annotation.RequestBody;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.bind.annotation.RestController;
16
17
import com.fasterxml.jackson.core.JsonProcessingException;
18
19
import edu.ucsb.cs156.gauchoride.entities.DriverAvailability;
20
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
21
import edu.ucsb.cs156.gauchoride.repositories.DriverAvailabilityRepository;
22
import io.swagger.v3.oas.annotations.Operation;
23
import io.swagger.v3.oas.annotations.Parameter;
24
import io.swagger.v3.oas.annotations.tags.Tag;
25
import lombok.extern.slf4j.Slf4j;
26
27
@Tag(name = "DriverAvailability")
28
@RequestMapping("/api/driverAvailability")
29
@RestController
30
@Slf4j
31
public class DriverAvailabilityController extends ApiController{
32
    
33
    @Autowired
34
    DriverAvailabilityRepository driverAvailabilityRepository;
35
36
    //Allows driver to create and post new availability
37
    @Operation(summary= "Create a new driver availability")
38
    @PreAuthorize("hasRole('ROLE_DRIVER')")
39
    @PostMapping("/new")
40
    public DriverAvailability postDriverAvailability(
41
            @Parameter(name="driverId") @RequestParam long driverId,
42
            @Parameter(name="day") @RequestParam String day,
43
            @Parameter(name="startTime") @RequestParam String startTime,
44
            @Parameter(name="endTime") @RequestParam String endTime,
45
            @Parameter(name="notes") @RequestParam String notes)
46
            throws JsonProcessingException {
47
48
49
        log.info("notes={}", notes);
50
51
        DriverAvailability driverAvailability = new DriverAvailability();
52 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED
        driverAvailability.setDriverId(driverId);
53 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        driverAvailability.setDay(day);
54 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        driverAvailability.setStartTime(startTime);
55 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        driverAvailability.setEndTime(endTime);
56 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        driverAvailability.setNotes(notes);
57
58
        DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability);
59
60 1 1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED
        return savedDriverAvailability;
61
    }
62
63
    //GET all availability submissions for the current user.
64
    @Operation(summary = "Get all driver availabilites owned by the current user")
65
    @PreAuthorize("hasRole('ROLE_DRIVER')")
66
    @GetMapping("")
67
    public Iterable<DriverAvailability> allApplications() {
68
        Iterable<DriverAvailability> availabilities;
69
        availabilities = driverAvailabilityRepository.findAllByDriverId(getCurrentUser().getUser().getId());
70 1 1. allApplications : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allApplications → KILLED
        return availabilities;
71
    }
72
73
    //GET a single availability by ID if owned by the current user
74
    @Operation(summary = "Get a single availability but only if owned by the current user")
75
    @PreAuthorize("hasRole('ROLE_DRIVER')")
76
    @GetMapping("id")
77
    public DriverAvailability getById(
78
                    @Parameter(name="id", description = "Long, Id of the driver availability to get", 
79
                    required = true)  
80
                    @RequestParam Long id) 
81
    {
82
        DriverAvailability availability;
83
        availability = driverAvailabilityRepository.findById(id)
84 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getById$0 → KILLED
                    .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
85 1 1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getById → KILLED
        return availability;
86
    }
87
88
    //Edits an availability if owned by current user
89
    @Operation(summary = "Edit an existing driver availability but only if it is owned by the current user")
90
    @PreAuthorize("hasRole('ROLE_DRIVER')")
91
    @PutMapping("")
92
    public ResponseEntity<Object> updateDriverAvailability(
93
                            @Parameter(name="id", description="long, Id of the driver availability to be edited", 
94
                            required = true)
95
                            @RequestParam Long id,
96
                            @RequestBody @Valid DriverAvailability incoming)
97
    {
98
        DriverAvailability availability;
99
100
        availability = driverAvailabilityRepository.findById(id)
101 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));
102
103 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED
        availability.setDriverId(incoming.getDriverId());
104 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        availability.setDay(incoming.getDay());
105 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        availability.setStartTime(incoming.getStartTime());
106 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        availability.setEndTime(incoming.getEndTime());
107 1 1. updateDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        availability.setNotes(incoming.getNotes());
108
109
        driverAvailabilityRepository.save(availability);
110 1 1. updateDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::updateDriverAvailability → KILLED
        return ResponseEntity.ok(availability);
111
112
    }
113
114
    //DELETE for driver Availability
115
    @Operation(summary= "Delete a driver availability")
116
    @PreAuthorize("hasRole('ROLE_DRIVER')")
117
    @DeleteMapping("")
118
    public Object deleteDriverAvailability(
119
            @Parameter(name="id") @RequestParam Long id) {
120
        DriverAvailability availability = driverAvailabilityRepository.findById(id)
121 1 1. lambda$deleteDriverAvailability$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deleteDriverAvailability$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
122
123 1 1. deleteDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED
        driverAvailabilityRepository.delete(availability);
124 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));
125
    }
126
127
    //Lets Admin GET a single availability by ID
128
    @Operation(summary = "Admin can get a single availability by id")
129
    @PreAuthorize("hasRole('ROLE_ADMIN')")
130
    @GetMapping("admin")
131
    public DriverAvailability adminGetById(
132
                    @Parameter(name="id", description = "Long, Id of the driver availability to get", 
133
                    required = true)  
134
                    @RequestParam Long id) 
135
    {
136
        DriverAvailability availability;
137
        availability = driverAvailabilityRepository.findById(id)
138 1 1. lambda$adminGetById$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$adminGetById$3 → KILLED
                    .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
139 1 1. adminGetById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::adminGetById → KILLED
        return availability;
140
    }
141
142
    //Lets admins get all driver availabilties
143
    @Operation(summary= "List all driver availabilities")
144
    @PreAuthorize("hasRole('ROLE_ADMIN')")
145
    @GetMapping("/admin/all")
146
    public Iterable<DriverAvailability> allDriverAvailabilities() {
147
        Iterable<DriverAvailability> availabilities = driverAvailabilityRepository.findAll();
148 1 1. allDriverAvailabilities : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilities → KILLED
        return availabilities;
149
    }
150
151
}

Mutations

52

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_can_post_a_new_driverAvailability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED

53

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_can_post_a_new_driverAvailability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED

54

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_can_post_a_new_driverAvailability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED

55

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_can_post_a_new_driverAvailability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED

56

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_can_post_a_new_driverAvailability()]
removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED

60

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_can_post_a_new_driverAvailability()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED

70

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

84

1.1
Location : lambda$getById$0
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_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getById$0 → KILLED

85

1.1
Location : getById
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_get_by_id_when_the_id_exists_and_user_id_matches()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getById → KILLED

101

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:driver_cannot_edit_availability_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updateDriverAvailability$1 → KILLED

103

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

104

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

105

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

106

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

107

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

110

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

121

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

123

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

124

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

138

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

139

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

148

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

Active mutators

Tests examined


Report generated by PIT 1.7.3