@PutMapping("/create") public Book create(Map<String, Object> map) 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; } public BookStoreController(BooksRepository repo, Boolean bool, List<String> keys) { this.repo = repo; if (Boolean.TRUE.equals(bool)) { // check first key if(keys != null && !keys.isEmpty()){ String firstKey = keys.get(0); if (firstKey == "public") { for (String key : keys){ // ... some logic log.debug("Using key {}", key); }; } } } }
Java
Tell us about your work experience: companies, projects, technologies.
@PutMapping("/create") public Book create(Map<String, Object> map) 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(); }
if (Boolean.TRUE.equals(bool)) { // check first key String firstKey = keys.iterator().next(); if (firstKey == "public") { keys.stream().forEach(key -> { // ... some logic log.warn("Using key " + key); }); } } public BookStoreController(BooksRepository repo, Boolean bool, List<String> keys) { this.repo = repo; if (Boolean.TRUE.equals(bool)) { // check first key String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... some logic log.warn("Using key " + 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) { // check first key String firstKey = (String) ((ArrayList) keys).get(0); if (firstKey == "public") { keys.stream().forEach(key -> { // ... some logic log.warn("Using key " + key); }); } } } @PutMapping("/create") public Book create(Map<String, Object> map) throws Exception { System.out.println("Check if book exists " + map); }
Tell me more about microservice architecture at your last workplace: how many services, how they interacted.
What were PostgreSQL and Redis used for?
Tell me more about the Quartz and Redis-based service: how it worked, how it scaled.
@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("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(); }