Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. @PostMapping("/rent")
  2. public ResponseEntity<HttpStatus> bikeRent(@RequestBody BikeRentDTO bikeRentDTO){
  3. Optional<Stand> optionalStand = standRepository.findById(bikeRentDTO.getStandId());
  4. Optional<Bike> optionalBike = bikeRepository.findById(bikeRentDTO.getBikeId());
  5. if (optionalStand.isPresent() && optionalBike.isPresent()){
  6. Bike bike = optionalBike.get();
  7. Stand stand = optionalStand.get();
  8. if (stand.getBike().getId() == bike.getId()){
  9. stand.setBike(null);
  10. stand.setIsAvailable(Stand.available.YES);
  11. bike.setRented(Bike.isRented.YES);
  12. standRepository.save(stand);
  13. bikeRepository.save(bike);
  14. return new ResponseEntity<>(HttpStatus.OK);
  15. }
  16. }
  17. return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement