ShiftController.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.Shift;
7
import edu.ucsb.cs156.gauchoride.repositories.ShiftRepository;
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.time.LocalTime;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.http.ResponseEntity;
16
import org.springframework.security.access.prepost.PreAuthorize;
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.PathVariable;
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
30
@Api(description = "Shift information")
31
@RequestMapping("/api/shift")
32
@RestController
33
public class ShiftController extends ApiController {
34
    @Autowired
35
    ShiftRepository shiftRepository;
36
37
    @Autowired
38
    ObjectMapper mapper;
39
40
    @ApiOperation(value = "Get a list of all shifts")
41
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')")
42
    @GetMapping("/all")
43
    public ResponseEntity<String> allShifts()
44
            throws JsonProcessingException {
45
        Iterable<Shift> shifts = shiftRepository.findAll();
46
        String body = mapper.writeValueAsString(shifts);
47 1 1. allShifts : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::allShifts → KILLED
        return ResponseEntity.ok().body(body);
48
    }
49
50
    @ApiOperation(value = "Get shift by id")
51
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')")
52
    @GetMapping("/get")
53
    public Shift shiftByID(
54
            @ApiParam(name = "id", type = "Long", value = "id number of shift to get", example = "1", required = true) @RequestParam Long id)
55
            throws JsonProcessingException {
56
        Shift shift = shiftRepository.findById(id)
57 1 1. lambda$shiftByID$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::lambda$shiftByID$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Shift.class, id));
58 1 1. shiftByID : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::shiftByID → KILLED
        return shift;
59
    }
60
61
    @ApiOperation(value = "Create a new shift for the table")
62
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')")
63
    @PostMapping("/post")
64
    public Shift postShift(
65
        @ApiParam("day") @RequestParam String day,
66
        @ApiParam("shiftStart") @RequestParam String shiftStart,
67
        @ApiParam("shiftEnd") @RequestParam String shiftEnd,
68
        @ApiParam("driverID") @RequestParam long driverID ,
69
        @ApiParam("driverBackupID") @RequestParam long driverBackupID
70
        )
71
        {
72
73
        Shift shift = new Shift();
74
75 1 1. postShift : removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDriverID → KILLED
        shift.setDriverID(getCurrentUser().getUser().getId());
76 1 1. postShift : removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDay → KILLED
        shift.setDay(day);
77 1 1. postShift : removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setShiftStart → KILLED
        shift.setShiftStart(shiftStart);
78 1 1. postShift : removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setShiftEnd → KILLED
        shift.setShiftEnd(shiftEnd);
79 1 1. postShift : removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDriverBackupID → KILLED
        shift.setDriverBackupID(driverBackupID);
80
81
        Shift savedShift = shiftRepository.save(shift);
82
83 1 1. postShift : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::postShift → KILLED
        return savedShift;
84
    }
85
}

Mutations

47

1.1
Location : allShifts
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:logged_in_admin_can_get_all_shifts()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::allShifts → KILLED

57

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

58

1.1
Location : shiftByID
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:test_that_logged_in_driver_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::shiftByID → KILLED

75

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDriverID → KILLED

76

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDay → KILLED

77

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setShiftStart → KILLED

78

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setShiftEnd → KILLED

79

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
removed call to edu/ucsb/cs156/gauchoride/entities/Shift::setDriverBackupID → KILLED

83

1.1
Location : postShift
Killed by : edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.ShiftControllerTests]/[method:a_driver_can_post_a_new_shift()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ShiftController::postShift → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3