IndividualRidesController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import edu.ucsb.cs156.gauchoride.entities.IndividualRides;
4
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.gauchoride.repositories.IndividualRidesRepository;
6
import io.swagger.annotations.Api;
7
import io.swagger.annotations.ApiOperation;
8
import io.swagger.annotations.ApiParam;
9
import lombok.extern.slf4j.Slf4j;
10
11
import com.fasterxml.jackson.core.JsonProcessingException;
12
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
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
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.List;
30
import java.time.LocalDate;
31
import java.time.LocalDateTime;
32
33
@Api(description = "IndividualRides")
34
@RequestMapping("/api/individualRides")
35
@RestController
36
@Slf4j
37
public class IndividualRidesController extends ApiController {
38
 
39
    @Autowired
40
    IndividualRidesRepository individualRidesRepository;
41
    
42
    @ApiOperation(value = "List all individualRides")
43
    @PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')")
44
    @GetMapping("/all")
45
    public Iterable<IndividualRides> allIndividualRides() {
46
        Iterable<IndividualRides> individualRides = individualRidesRepository.findAll();
47 1 1. allIndividualRides : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRides → KILLED
        return individualRides;
48
    }
49
50
    @ApiOperation(value = "List all individualRides with driverId")
51
@PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')")
52
    @GetMapping("/allWithDriverId")
53
    public Iterable<IndividualRides> allIndividualRidesWithDriverId( 
54
        @ApiParam("driverId") @RequestParam Long id) {
55
56
        Iterable<IndividualRides> individualRides = individualRidesRepository.findAll();
57
        List<IndividualRides> filteredList = new ArrayList<>();
58
59
        for(IndividualRides ride : individualRides){
60 1 1. allIndividualRidesWithDriverId : negated conditional → KILLED
            if(ride.getDriverId() == id)
61
                filteredList.add(ride);
62
        }
63
64 1 1. allIndividualRidesWithDriverId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithDriverId → KILLED
        return (Iterable<IndividualRides>)filteredList;
65
    }
66
67
    @ApiOperation(value = "List all individualRides with riderId")
68
@PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')")
69
    @GetMapping("/allWithRiderId")
70
    public Iterable<IndividualRides> allIndividualRidesWithRiderId( 
71
        @ApiParam("riderId") @RequestParam Long id) {
72
73
        Iterable<IndividualRides> individualRides = individualRidesRepository.findAll();
74
        List<IndividualRides> filteredList = new ArrayList<>();
75
76
        for(IndividualRides ride : individualRides){
77 1 1. allIndividualRidesWithRiderId : negated conditional → KILLED
            if(ride.getRiderId() == id)
78
                filteredList.add(ride);
79
        }
80
81 1 1. allIndividualRidesWithRiderId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithRiderId → KILLED
        return (Iterable<IndividualRides>)filteredList;
82
    }
83
84
    @ApiOperation(value = "Get a single ride")
85
@PreAuthorize("hasRole('ROLE_DRIVER') || hasRole('ROLE_ADMIN') || hasRole('ROLE_RIDER')")
86
    @GetMapping("")
87
    public IndividualRides getById(
88
            @ApiParam("id") @RequestParam Long id) {
89
                IndividualRides individualRide = individualRidesRepository.findById(id)
90 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id));
91
92 1 1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::getById → KILLED
        return individualRide;
93
    }
94
95
    @ApiOperation(value = "Delete a ride")
96
    @PreAuthorize("hasRole('ROLE_ADMIN')")
97
    @DeleteMapping("")
98
    public Object deleteRide(
99
            @ApiParam("id") @RequestParam Long id) {
100
        IndividualRides individualRide = individualRidesRepository.findById(id)
101 1 1. lambda$deleteRide$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$deleteRide$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id));
102
103 1 1. deleteRide : removed call to edu/ucsb/cs156/gauchoride/repositories/IndividualRidesRepository::delete → KILLED
            individualRidesRepository.delete(individualRide);
104 1 1. deleteRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::deleteRide → KILLED
        return genericMessage("Ride with id %s deleted".formatted(id));
105
    }
106
107
    @ApiOperation(value = "Update a single ride")
108
    @PreAuthorize("hasRole('ROLE_ADMIN')")
109
    @PutMapping("")
110
    public IndividualRides updateIndividualRide(
111
            @ApiParam("id") @RequestParam Long id,
112
            @RequestBody @Valid IndividualRides incoming) {
113
114
        IndividualRides individualRide = individualRidesRepository.findById(id)
115 1 1. lambda$updateIndividualRide$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::lambda$updateIndividualRide$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IndividualRides.class, id));
116
117 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED
        individualRide.setDriverId(incoming.getDriverId());
118 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED
        individualRide.setRiderId(incoming.getRiderId());
119 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED
        individualRide.setStartTime(incoming.getStartTime());
120 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED
        individualRide.setEndTime(incoming.getEndTime());
121 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED
        individualRide.setPickupLocation(incoming.getPickupLocation());
122 1 1. updateIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED
        individualRide.setDropoffLocation(incoming.getDropoffLocation());
123
        individualRidesRepository.save(individualRide);
124
125 1 1. updateIndividualRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::updateIndividualRide → KILLED
        return individualRide;
126
    }
127
128
    @ApiOperation(value = "Create a new individualRide")
129
    @PreAuthorize("hasRole('ROLE_ADMIN')")
130
    @PostMapping("/post")
131
    public IndividualRides postIndividualRide(
132
        @ApiParam("driverId") @RequestParam Long driverId,
133
        @ApiParam("riderId") @RequestParam Long riderId,
134
        @ApiParam("startTime") @RequestParam String startTimeString,
135
        @ApiParam("endTime") @RequestParam String endTimeString,
136
        @ApiParam("pickupLocation") @RequestParam String pickupLocation,
137
        @ApiParam("dropoffLocation") @RequestParam String dropoffLocation
138
        )
139
    {
140
        LocalDateTime startTime = LocalDateTime.parse(startTimeString);
141
        LocalDateTime endTime = LocalDateTime.parse(endTimeString);
142
143
        IndividualRides individualRide = new IndividualRides();
144 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED
        individualRide.setDriverId(driverId);
145 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED
        individualRide.setRiderId(riderId);
146 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED
        individualRide.setStartTime(startTime);
147 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED
        individualRide.setEndTime(endTime);
148 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED
        individualRide.setPickupLocation(pickupLocation);
149 1 1. postIndividualRide : removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED
        individualRide.setDropoffLocation(dropoffLocation);
150
151
        IndividualRides savedRide = individualRidesRepository.save(individualRide);
152 1 1. postIndividualRide : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::postIndividualRide → KILLED
        return savedRide;
153
    }
154
}
155

Mutations

47

1.1
Location : allIndividualRides
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:logged_in_user_can_get_all_rides()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRides → KILLED

60

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

64

1.1
Location : allIndividualRidesWithDriverId
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:logged_in_user_can_get_all_rides_with_driver_id()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithDriverId → KILLED

77

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

81

1.1
Location : allIndividualRidesWithRiderId
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:logged_in_user_can_get_all_rides_with_rider_id()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::allIndividualRidesWithRiderId → KILLED

90

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

92

1.1
Location : getById
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:test_getRides()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::getById → KILLED

101

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

103

1.1
Location : deleteRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_delete_a_ride()]
removed call to edu/ucsb/cs156/gauchoride/repositories/IndividualRidesRepository::delete → KILLED

104

1.1
Location : deleteRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_delete_a_ride()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::deleteRide → KILLED

115

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

117

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED

118

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED

119

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED

120

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED

121

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED

122

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED

125

1.1
Location : updateIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:admin_can_edit_an_existing_ride()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::updateIndividualRide → KILLED

144

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDriverId → KILLED

145

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setRiderId → KILLED

146

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setStartTime → KILLED

147

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setEndTime → KILLED

148

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setPickupLocation → KILLED

149

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
removed call to edu/ucsb/cs156/gauchoride/entities/IndividualRides::setDropoffLocation → KILLED

152

1.1
Location : postIndividualRide
Killed by : edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.IndividualRidesControllerTest]/[method:an_admin_user_can_post_a_new_ride()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/IndividualRidesController::postIndividualRide → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3