This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AllArgsConstructor | |
@Service | |
public class BookService { | |
@Autowired | |
private BookRepository bookRepository; | |
public Book findById(String id) { | |
return bookRepository.findById(id).orElse(Book.builder().build()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("books") | |
@RequiredArgsConstructor | |
public class BookController { | |
private final BookService bookService; | |
@GetMapping("/{id}") | |
public Book findById(@PathVariable(name = "id") String id) { | |
return bookService.findById(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "1231415-f785b-4c794--2134bffcd3", | |
"title":"Animal Farm", | |
"author":{ | |
"name": "George Orwell" | |
}, | |
"tags": ["fiction"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("books") | |
public class BookController { | |
@Autowired | |
private BookService bookService; | |
@GetMapping("/{id}") | |
public BookDto getById(@PathVariable(name = "id") Integer id) { | |
return bookService.getById(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FeignClient(value = "bookApiClient", url = "${book-api.url}", configuration = BookClientFeignConfiguration.class) | |
public interface BookApiClient { | |
@GetMapping(value = "/books/{id}") | |
BookResponse getById(@PathVariable String id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BookClientFeignConfiguration { | |
private static final int CONNECT_TIMEOUT_MILLIS = 5000; | |
private static final int READ_TIMEOUT_MILLIS = 5000; | |
@Bean | |
public Contract useBookClientFeignAnnotations() { | |
return new SpringMvcContract(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BookClientErrorDecoder implements ErrorDecoder { | |
@Override | |
public Exception decode(String methodKey, Response response) { | |
return new Default().decode(methodKey, response); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("books") | |
@RequiredArgsConstructor | |
public class BookController { | |
private final BookService bookService; | |
@GetMapping | |
public List<Book> findAll() { | |
return bookService.findAll(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AllArgsConstructor | |
@Service | |
public class BookService { | |
@Autowired | |
private BookRepository bookRepository; | |
public List<Book> findAll() { | |
Iterable<Book> book = bookRepository.findAll(); | |
List<Book> books = new ArrayList<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
@Setter | |
@RequiredArgsConstructor | |
@AllArgsConstructor | |
@Builder | |
@Document(indexName = "book") | |
public class Book { | |
@Id | |
private String id; |