Sobes.tech

Java

@PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Vérifier si le livre existe " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Le livre existe déjà"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Livre {} par {} a été créé avec l'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)) { // vérifier la première clé if(keys != null && !keys.isEmpty()){ String firstKey = keys.get(0); if (firstKey == "public") { for (String key : keys){ // ... une logique log.debug("Utilisation de la clé {}", key); }; } } } }

263

@PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Vérifier si le livre existe " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Le livre existe déjà"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Livre {} par {} a été créé avec l'id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } @GetMapping("/get") public Book get(@QueryParam("id") String id) { log.debug("Obtenir le livre " + id); return repo.findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); }

173

if (Boolean.TRUE.equals(bool)) { // vérifier la première clé String firstKey = keys.iterator().next(); if (firstKey == "public") { keys.stream().forEach(key -> { // ... une certaine logique log.warn("Utilisation de la clé " + key); }); } } public BookStoreController(BooksRepository repo, Boolean bool, List<String> keys) { this.repo = repo; if (Boolean.TRUE.equals(bool)) { // vérifier la première clé String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... une certaine logique log.warn("Utilisation de la clé " + key); }); } } }

164

importer jakarta.persistence.Id; importer jakarta.persistence.Table; importer jakarta.ws.rs.QueryParam; importer lombok.Data; importer 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) { // vérifier la première clé String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... une logique log.warn("Utilisation de la clé " + key); }); } } } @PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Vérifier si le livre existe " + map); }

158

Parlez-nous plus en détail de l'architecture microservices dans votre dernier emploi : combien de services, comment ils interagissaient

155

@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; }

140

@PutMapping("/create") public Book create(@RequestBody CreateBook request) throws Exception { System.out.println("Vérifier si le livre existe " + map); Book book = new ObjectMapper().convertValue(map, Book.class); Book b = repo.findByTitle(book.getTitle()); if (b != null) { throw new Exception("Le livre existe déjà"); } book.setId(UUID.randomUUID().toString()); repo.save(book); log.debug("Livre {} par {} a été créé avec l'id {}", book.getTitle(), book.getAuthor(), book.getId()); return book; } @GetMapping("/get") public Book get(@QueryParam("id") String id) { log.debug("Obtenir le livre " + id); return repo.findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); } @GetMapping("/{id}") public Book get(@RequestParam("id") String id) { log.debug("Obtenir le livre ", id); return repo.findById(id).orElseThrow(() -> new BookAlreadyExeption("livre non trouvé")) findAll().stream() .filter(b -> b.getId().equals(id)) .findFirst().get(); }

129