@PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Verifica dacă cartea există " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Cartea deja există"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Cartea {} de {} a fost creată cu id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } public BookStoreController(BooksRepository repo, Boolean bool, List<String> keys) { this.repo = repo; if (Boolean.TRUE.equals(bool)) { // verifică prima cheie if(keys != null && !keys.isEmpty()){ String firstKey = keys.get(0); if (firstKey == "public") { for (String key : keys){ // ... unele logică log.debug("Folosind cheia {}", key); }; } } } }
Java
Spuneți-ne despre experiența dvs. profesională: companii, proiecte, tehnologii
@PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Verifica dacă cartea există " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Cartea există deja"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Cartea {} de {} a fost creată cu id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } @GetMapping("/get") public Book get(@QueryParam("id") String id) { log.debug("Obține cartea " + id); return repo.findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); }
if (Boolean.TRUE.equals(bool)) { // verifică prima cheie String firstKey = keys.iterator().next(); if (firstKey == "public") { keys.stream().forEach(key -> { // ... unele logică log.warn("Folosind cheia " + key); }); } } public BookStoreController(BooksRepository repo, Boolean bool, List<String> keys) { this.repo = repo; if (Boolean.TRUE.equals(bool)) { // verifică prima cheie String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... unele logică log.warn("Folosind cheia " + key); }); } } }
import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.ws.rs.QueryParam; import lombok.Data; import lombok.extern.log4j.Log4j2; @Log4j2 @Service @RestController("/store/book") public class BookStoreController { private final BooksRepository repo; public BookStoreController(BooksRepository repo, Boolean bool, Collection keys) { this.repo = repo; if (bool) { // текшерүү биринчи ачкыч String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... кээ бир логика log.warn("Ачкычты колдонуу " + key); }); } } } @PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Китеп бар экенин текшерүү " + map); }
Spuneți mai multe despre arhitectura microserviciilor la ultimul loc de muncă: câte servicii, cum interacționau
Pentru ce scopuri a fost folosit PostgreSQL și Redis?
Spuneți mai multe despre serviciul bazat pe Quartz și Redis: cum a funcționat, cum s-a scalat
@Data @Entity @Table(name = "_store") public static class Book { @Id private String id; private String title; private String author; private int price; @Transient private String tmp; @Enumerated(EnumType.STRING) private BookType type; } public enum BookType { COMMON, PREMIUM; }
@PutMapping("/create") public Book create(@RequestBody CreateBook request) throws Exception { System.out.println("Verifică dacă cartea există " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Cartea deja există"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Cartea {} de {} a fost creată cu id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } @GetMapping("/get") public Book get(@QueryParam("id") String id) { log.debug("Obține cartea " + id); return repo.findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); } @GetMapping("/{id}") public Book get(@RequestParam("id") String id) { log.debug("Obține cartea ", id); return repo.findById(id).orElseThrow(() -> new BookAlreadyExeption("carte negăsită")) findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); }