Merge pull request #154 from nitta-lab-2024/GetOneBook
bookIdを指定して本を一冊取得できるようにした。
commit 4458ef9c9c6b676350dd9d905e77176062f9a23e
2 parents a12b54e + 49eb0fe
渡辺智裕 authored on 8 Oct
Showing 1 changed file
View
21
app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java
 
private final Retrofit retrofit;
private final BooksRest booksRest;
private final MutableLiveData<HashMap<Integer, Book>> booksLiveData;
private final MutableLiveData<Book> book;
private final MutableLiveData<String> titleLiveData;
private final MutableLiveData<String> colorLiveData;
private final MutableLiveData<String> publicityLiveData;
private final MutableLiveData<String> favoritedLiveData;
this.titleLiveData = new MutableLiveData<>();
this.colorLiveData = new MutableLiveData<>();
this.publicityLiveData = new MutableLiveData<>();
this.favoritedLiveData = new MutableLiveData<>();
this.book = new MutableLiveData<>();
}
 
public MutableLiveData<HashMap<Integer, Book>> getBookLiveData() { return this.booksLiveData;}//本の一覧を返す
public MutableLiveData<String> getTitleLiveData() {return this.titleLiveData;}//本のタイトルを返す
public MutableLiveData<String> getPublicityLiveData() {return this.publicityLiveData;}//本の公開状態を返す
 
public MutableLiveData<Book> getBook() {return this.book;};
 
public void createBook(String accountId, String title, String color, Boolean publicity, String token ){
Call<HashMap<Integer, Book>> call = booksRest.createBook(accountId , title, color, publicity, token);
 
}
});
}
 
public void loadBook(String accountId, String token, int bookId) {
Call<Book> call = booksRest.getBook(accountId, bookId, token);
call.enqueue(new Callback<Book>() {
@Override
public void onResponse(Call<Book> call, Response<Book> response) {
if(response.isSuccessful()) {
book.setValue(response.body());
}
}
 
@Override
public void onFailure(Call<Book> call, Throwable t) {
System.out.println("network error");
}
});
}
 
public void deleteBook(String accountId, Integer bookId, String token){
Call<HashMap<Integer, Book>> call = booksRest.deleteBook(accountId, bookId, token);
 
call.enqueue(new Callback<HashMap<Integer, Book>>() {