Skip to content

Instantly share code, notes, and snippets.

@Jet-C
Last active December 1, 2019 01:17
Show Gist options
  • Save Jet-C/462820dcd33b744481aba7c754a1cfdc to your computer and use it in GitHub Desktop.
Save Jet-C/462820dcd33b744481aba7c754a1cfdc to your computer and use it in GitHub Desktop.
Vehicle controller
@RestController
@RequestMapping("/demo")
public class VehicleController {
@Autowired
VehicleService vehicleService;
@ApiOperation(value = "Retrieves a list of all vehicle records")
@GetMapping(value = "/vehicles", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Vehicle>> getAllVehicles() {
List<Vehicle> vehicles = vehicleService.getAllVehicles();
if (vehicles.isEmpty()) {
throw new VehicleNotFoundException("No vehicle records were found");
}
return new ResponseEntity<List<Vehicle>>(vehicles, HttpStatus.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment