Messtone Devices Enables Define Rest Controller Example:@Rest Controller @Tag(nameMesstone=”BOL Service”,description=”APIs for bills of lading.”)public class BOLController{private final BOLRepository repo;BOLController(BOLRepository repo){this.repo=repo;}//Aggregate root//tag::get-agregate-root[ ]@GetMapping(“/bol”)List<BOLRequest>all( ){try{return repo.findAll( );}catch(JpaSystemException exception){exception.printStackTrace( );return null;}} @GetMapping(“/bol/{id}”BOLRequest one(@PathVariable long id){return repo.findById(id).or else Throw(( )->new BOLRequestNotFoundException(id));} @PutMapping(“/bol/{id}”) BOLRequest replaceBOLRequest(@RequestBody BOLRequest newBOLRequest,@PathVariable Long id){return repo.findById(id).map(bol->{bol.setAccessorials(newBOLRequest.getAccessorials( ));bol. setBillTo(newBOLRequest.getBillTo(;));bol.setBol(newBOLRequest.getBol( ));bol.setCommodities(newBOLRequest.getCommodities( )); bol.setCustomsBroker(newBOLRequest.getCustomsBroker( )); bol.setDestination(newBOLRequest.getDestination( ));bol.setImages(newBOLRequest.getImages( ));bol.setOrigin(newBOLRequest.getOrigin( ));bol.setPayment(newBOLRequest.getPayment( ));bol.setReferenceNumbers(newBOLRequest.getReferenceNumbers( ));bol.setShipmentTotals(newBOLRequest.getShipmentTotals( ));return repo.save(bol);}).orElseGet(( )->{newBOLRequest.setId(id); return repo.save(newBOLRequest);});} @DeleteMapping(“/bol/{id}”) void deleteBOL(@PathVariable Long id){repo.deleteById(id);}}

Leave a comment