| 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 | ||
| 11 | ||
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.http.ResponseEntity; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestParam; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 23 | import io.swagger.v3.oas.annotations.Operation; | |
| 24 | import io.swagger.v3.oas.annotations.Parameter; | |
| 25 | ||
| 26 | @Tag(name = "Driver Information") | |
| 27 | @RequestMapping("/api/drivers/all") | |
| 28 | @RestController | |
| 29 | public class DriversController extends ApiController{ | |
| 30 | @Autowired | |
| 31 | UserRepository userRepository; | |
| 32 | ||
| 33 | @Autowired | |
| 34 | ObjectMapper mapper; | |
| 35 | ||
| 36 | @Operation(summary = "Get a list of all drivers") | |
| 37 | @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER') || hasRole('ROLE_USER')") | |
| 38 | @GetMapping("") | |
| 39 | public ResponseEntity<String> drivers() | |
| 40 | throws JsonProcessingException { | |
| 41 | ||
| 42 | Iterable<User> drivers=userRepository.findByDriver(true); | |
| 43 | ||
| 44 | | |
| 45 | | |
| 46 | | |
| 47 | ||
| 48 | | |
| 49 | String body = mapper.writeValueAsString(drivers); | |
| 50 |
1
1. drivers : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/DriversController::drivers → KILLED |
return ResponseEntity.ok().body(body); |
| 51 | } | |
| 52 | ||
| 53 | ||
| 54 | } | |
Mutations | ||
| 50 |
1.1 |