forked from howtoprogram/Java-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookRepositoryImplFeign.java
More file actions
57 lines (39 loc) · 1.7 KB
/
Copy pathBookRepositoryImplFeign.java
File metadata and controls
57 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.howtoprogram.repository.feign;
import java.util.List;
import com.howtoprogram.domain.Book;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
public class BookRepositoryImplFeign {
private static final String URI_BOOK = "http://localhost:8080";
public Book updateBook(Book book) throws Exception {
BookResourceFeign bookResource = Feign.builder().encoder(new JacksonEncoder())
.decoder(new JacksonDecoder()).target(BookResourceFeign.class, URI_BOOK);
Book updatedBook = bookResource.updateBook(book.getId(), book);
return updatedBook;
}
public Book createBook(Book book) throws Exception {
BookResourceFeign bookResource = Feign.builder().encoder(new JacksonEncoder())
.decoder(new JacksonDecoder()).target(BookResourceFeign.class, URI_BOOK);
Book createdBook = bookResource.createBook(book);
return createdBook;
}
public List<Book> getAllBooks() throws Exception {
BookResourceFeign bookResource = Feign.builder().encoder(new JacksonEncoder())
.decoder(new JacksonDecoder()).target(BookResourceFeign.class, URI_BOOK);
return bookResource.getAllBooks();
}
public static void main(String[] args) throws Exception {
BookRepositoryImplFeign bookRepository = new BookRepositoryImplFeign();
Book book = bookRepository.getAllBooks().get(0);
bookRepository.deleteBook(book.getId());
}
public void deleteBook(Long id) {
BookResourceFeign bookResource = Feign.builder().encoder(new JacksonEncoder())
.decoder(new JacksonDecoder()).target(BookResourceFeign.class, URI_BOOK);
bookResource.deleteBook(id);
}
public Book findBookById(Long id) {
return null;
}
}