ВопросSeniorСТЭП ЛОДЖИК (STEP LOGIC)22 просмотра

@PutMapping("/create") public Book create(@RequestBody CreateBook request) throws Exception { System.out.println("Check if book exists " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Book already exists"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Book {} by {} is created with id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } @GetMapping("/get") public Book get(@QueryParam("id") String id) { log.debug("Get book " + id); return repo.findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); } @GetMapping("/{id}") public Book get(@RequestParam("id") String id) { log.debug("Get book ", id); return repo.findById(id).orElseThrow(() -> new BookAlreadyExeption("book not find")) findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); }