DriverAvailabilityController.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.DriverAvailability;
7
import edu.ucsb.cs156.gauchoride.repositories.DriverAvailabilityRepository;
8
import edu.ucsb.cs156.gauchoride.repositories.UserRepository;
9
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
10
import edu.ucsb.cs156.gauchoride.models.CurrentUser;
11
12
import java.sql.Driver;
13
import java.time.LocalTime;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.http.ResponseEntity;
17
import org.springframework.security.access.prepost.PreAuthorize;
18
import org.springframework.web.bind.annotation.DeleteMapping;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PostMapping;
21
import org.springframework.web.bind.annotation.PathVariable;
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
import org.springframework.web.bind.annotation.PutMapping;
26
import org.springframework.web.bind.annotation.RequestBody;
27
28
import javax.validation.Valid;
29
30
import io.swagger.v3.oas.annotations.tags.Tag;
31
import io.swagger.v3.oas.annotations.Operation;
32
import io.swagger.v3.oas.annotations.Parameter;
33
34
35
@Tag(name = "DriverAvailability Information")
36
@RequestMapping("/api/driverAvailability")
37
@RestController
38
public class DriverAvailabilityController extends ApiController {
39
    @Autowired
40
    DriverAvailabilityRepository driverAvailabilityRepository;
41
42
    @Autowired
43
    ObjectMapper mapper;
44
45
    @Operation(summary = "Create a new driver availability for the table")
46
    @PreAuthorize("hasRole('ROLE_DRIVER')")
47
    @PostMapping("/new")
48
    public DriverAvailability postDriverAvailability(
49
        @Parameter(name="day") @RequestParam String day,
50
        @Parameter(name="startTime") @RequestParam String startTime,
51
        @Parameter(name="endTime") @RequestParam String endTime,
52
        @Parameter(name="notes") @RequestParam String notes
53
        )
54
        {
55
56
        DriverAvailability driverAvailability = new DriverAvailability();
57
58 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED
        driverAvailability.setDriverId(getCurrentUser().getUser().getId());
59 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        driverAvailability.setDay(day);
60 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        driverAvailability.setStartTime(startTime);
61 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        driverAvailability.setEndTime(endTime);
62 1 1. postDriverAvailability : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        driverAvailability.setNotes(notes);
63
64
        DriverAvailability savedDriverAvailability = driverAvailabilityRepository.save(driverAvailability);
65
66 1 1. postDriverAvailability : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::postDriverAvailability → KILLED
        return savedDriverAvailability;
67
        }
68
69
    @Operation(summary= "Delete Driver Availability")
70
    @PreAuthorize("hasRole('ROLE_DRIVER')")
71
    @DeleteMapping("")
72
    public Object deletemenuitem(
73
        @Parameter(name="id") @RequestParam Long id) 
74
        {
75
        DriverAvailability drivav = driverAvailabilityRepository.findById(id)
76 1 1. lambda$deletemenuitem$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$deletemenuitem$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
77
        
78 1 1. deletemenuitem : removed call to edu/ucsb/cs156/gauchoride/repositories/DriverAvailabilityRepository::delete → KILLED
         driverAvailabilityRepository.delete(drivav);
79 1 1. deletemenuitem : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::deletemenuitem → KILLED
        return genericMessage("Driver Availability with id %s deleted".formatted(id));
80
        }
81
82
    @Operation(summary = "Get a list of all driver availabilities")
83
    @PreAuthorize("hasRole('ROLE_ADMIN')")
84
    @GetMapping("/admin/all")
85
    public ResponseEntity<String> allDriverAvailabilities()
86
            throws JsonProcessingException {
87
        Iterable<DriverAvailability> driverAvailabilities = driverAvailabilityRepository.findAll();
88
        String body = mapper.writeValueAsString(driverAvailabilities);
89 1 1. allDriverAvailabilities : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilities → NO_COVERAGE
        return ResponseEntity.ok().body(body);
90
    }
91
92
    @Operation(summary = "Get driver availability by id")
93
    @PreAuthorize("hasRole('ROLE_ADMIN')")
94
    @GetMapping("/admin")
95
    public DriverAvailability driverAvailabilityByID(
96
            @Parameter(name = "id", description = "Long, id number of driver availability to get", example = "1", required = true) @RequestParam Long id)
97
            throws JsonProcessingException {
98
        DriverAvailability driverAvailability = driverAvailabilityRepository.findById(id)
99 1 1. lambda$driverAvailabilityByID$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$driverAvailabilityByID$1 → NO_COVERAGE
                .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
100 1 1. driverAvailabilityByID : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::driverAvailabilityByID → NO_COVERAGE
        return driverAvailability;
101
    }
102
    
103
104
    @Operation(summary= "Update Driver Availability")
105
    @PreAuthorize("hasRole('ROLE_DRIVER')")
106
    @PutMapping("")
107
    public DriverAvailability updatemenuitem(
108
            @Parameter(name="id") @RequestParam Long id,
109
            @RequestBody @Valid DriverAvailability incoming) {
110
111
        DriverAvailability drivav = driverAvailabilityRepository.findById(id)
112 1 1. lambda$updatemenuitem$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$updatemenuitem$2 → KILLED
        .orElseThrow(() -> new EntityNotFoundException(DriverAvailability.class, id));
113
114 1 1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDriverId → KILLED
        drivav.setDriverId(incoming.getDriverId());
115 1 1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setDay → KILLED
        drivav.setDay(incoming.getDay());
116 1 1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setStartTime → KILLED
        drivav.setStartTime(incoming.getStartTime());
117 1 1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setEndTime → KILLED
        drivav.setEndTime(incoming.getEndTime());
118 1 1. updatemenuitem : removed call to edu/ucsb/cs156/gauchoride/entities/DriverAvailability::setNotes → KILLED
        drivav.setNotes(incoming.getNotes());
119
120
        driverAvailabilityRepository.save(drivav);
121
122 1 1. updatemenuitem : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::updatemenuitem → KILLED
        return drivav;
123
    }
124
125
126
    @Operation(summary= "List all Driver Availability")
127
    @PreAuthorize("hasRole('ROLE_DRIVER')")
128
    @GetMapping("/all")
129
    public Iterable<DriverAvailability> allmenuitems() {
130
        Iterable<DriverAvailability> drivall = driverAvailabilityRepository.findAll();
131 1 1. allmenuitems : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allmenuitems → KILLED
        return drivall;
132
    }
133
134
135
    @Operation(summary= "Get Driver Availability")
136
    @PreAuthorize("hasRole('ROLE_DRIVER')")
137
    @GetMapping("")
138
    public DriverAvailability getById(
139
            @Parameter(name="id") @RequestParam Long id) {
140
        DriverAvailability drivav = driverAvailabilityRepository.findById(id)
141 1 1. lambda$getById$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$getById$3 → KILLED
                .orElseThrow(() -> new EntityNotFoundException( DriverAvailability.class, id));
142
143 1 1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::getById → KILLED
        return drivav;
144
    }
145
}

Mutations

58

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

59

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

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

61

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

62

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

66

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

76

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

78

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

79

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

89

1.1
Location : allDriverAvailabilities
Killed by : none
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::allDriverAvailabilities → NO_COVERAGE

99

1.1
Location : lambda$driverAvailabilityByID$1
Killed by : none
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::lambda$driverAvailabilityByID$1 → NO_COVERAGE

100

1.1
Location : driverAvailabilityByID
Killed by : none
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriverAvailabilityController::driverAvailabilityByID → NO_COVERAGE

112

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

114

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

115

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

116

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

117

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

118

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

122

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

131

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

141

1.1
Location : lambda$getById$3
Killed by : edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.DriverAvailabilityControllerTests]/[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/gauchoride/controllers/DriverAvailabilityController::lambda$getById$3 → KILLED

143

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

Active mutators

Tests examined


Report generated by PIT 1.7.3