Skip to content

Instantly share code, notes, and snippets.

View atesibrahim's full-sized avatar

Ibrahim Ates atesibrahim

View GitHub Profile
@atesibrahim
atesibrahim / BookService.java
Created July 19, 2022 14:10
Couchbase Example
@AllArgsConstructor
@Service
public class BookService {
@Autowired
private BookRepository bookRepository;
public Book findById(String id) {
return bookRepository.findById(id).orElse(Book.builder().build());
}
@atesibrahim
atesibrahim / BookController.java
Created July 19, 2022 14:08
Couchbase Example
@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);
{
"id": "1231415-f785b-4c794--2134bffcd3",
"title":"Animal Farm",
"author":{
"name": "George Orwell"
},
"tags": ["fiction"]
}
@atesibrahim
atesibrahim / BookContoller.java
Last active July 18, 2022 11:19
RESTful example
@RestController
@RequestMapping("books")
public class BookController {
@Autowired
private BookService bookService;
@GetMapping("/{id}")
public BookDto getById(@PathVariable(name = "id") Integer id) {
return bookService.getById(id);
@atesibrahim
atesibrahim / BookClientErrorDecoder.java
Last active July 16, 2022 14:51
Feign Error Decoder Configuration
public class BookClientErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
return new Default().decode(methodKey, response);
}
}
@atesibrahim
atesibrahim / BookClientFeignConfiguration.java
Last active July 16, 2022 14:51
Feign Client Configuration
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();
}
@atesibrahim
atesibrahim / BookApiClient.java
Last active July 16, 2022 14:50
Feign Client
@FeignClient(value = "bookApiClient", url = "${book-api.url}", configuration = BookClientFeignConfiguration.class)
public interface BookApiClient {
@GetMapping(value = "/books/{id}")
BookResponse getById(@PathVariable String id);
}
@RestController
@RequestMapping("books")
@RequiredArgsConstructor
public class BookController {
private final BookService bookService;
@GetMapping
public List<Book> findAll() {
return bookService.findAll();
@AllArgsConstructor
@Service
public class BookService {
@Autowired
private BookRepository bookRepository;
public List<Book> findAll() {
Iterable<Book> book = bookRepository.findAll();
List<Book> books = new ArrayList<>();
@Getter
@Setter
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "book")
public class Book {
@Id
private String id;