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.User; | |
7 | import edu.ucsb.cs156.gauchoride.repositories.UserRepository; | |
8 | ||
9 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
10 | import edu.ucsb.cs156.gauchoride.models.DriverInfo; | |
11 | ||
12 | import java.sql.Driver; | |
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.RequestMapping; | |
21 | import org.springframework.web.bind.annotation.RequestParam; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import io.swagger.v3.oas.annotations.tags.Tag; | |
25 | import io.swagger.v3.oas.annotations.Operation; | |
26 | import io.swagger.v3.oas.annotations.Parameter; | |
27 | ||
28 | @Tag(name = "Driver Information") | |
29 | @RequestMapping("/api/drivers") | |
30 | @RestController | |
31 | public class DriversController extends ApiController { | |
32 | @Autowired | |
33 | UserRepository userRepository; | |
34 | ||
35 | @Autowired | |
36 | ObjectMapper mapper; | |
37 | ||
38 | @Operation(summary = "Get a list of all drivers") | |
39 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
40 | @GetMapping("/all") | |
41 | public ResponseEntity<String> drivers() | |
42 | throws JsonProcessingException { | |
43 | ||
44 | Iterable<User> drivers = userRepository.findByDriver(true); | |
45 | ||
46 | String body = mapper.writeValueAsString(drivers); | |
47 |
1
1. drivers : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriversController::drivers → KILLED |
return ResponseEntity.ok().body(body); |
48 | } | |
49 | ||
50 | @Operation(summary = "Get user by id") | |
51 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')") | |
52 | @GetMapping("/get") | |
53 | public DriverInfo driver( | |
54 | @Parameter(name = "id", description = "Long, id number of user to get", example = "1", required = true) @RequestParam Long id) | |
55 | throws JsonProcessingException { | |
56 | User user = userRepository.findById(id) | |
57 |
1
1. lambda$driver$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriversController::lambda$driver$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(User.class, id)); |
58 | ||
59 | DriverInfo driverInfo = new DriverInfo(); | |
60 | ||
61 |
1
1. driver : negated conditional → KILLED |
if (user.getDriver()) { |
62 |
1
1. driver : removed call to edu/ucsb/cs156/gauchoride/models/DriverInfo::setIsDriver → KILLED |
driverInfo.setIsDriver(true); |
63 |
1
1. driver : removed call to edu/ucsb/cs156/gauchoride/models/DriverInfo::setEmail → KILLED |
driverInfo.setEmail(user.getEmail()); |
64 |
1
1. driver : removed call to edu/ucsb/cs156/gauchoride/models/DriverInfo::setFamilyName → KILLED |
driverInfo.setFamilyName(user.getFamilyName()); |
65 |
1
1. driver : removed call to edu/ucsb/cs156/gauchoride/models/DriverInfo::setGivenName → KILLED |
driverInfo.setGivenName(user.getGivenName()); |
66 | } | |
67 |
1
1. driver : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriversController::driver → KILLED |
return driverInfo; |
68 | } | |
69 | ||
70 | } | |
Mutations | ||
47 |
1.1 |
|
57 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
67 |
1.1 |