diff --git a/app/src/main/java/com/example/citrusclient/models/Book.java b/app/src/main/java/com/example/citrusclient/models/Book.java index f69ff74..19140a2 100644 --- a/app/src/main/java/com/example/citrusclient/models/Book.java +++ b/app/src/main/java/com/example/citrusclient/models/Book.java @@ -1,4 +1,33 @@ package com.example.citrusclient.models; public class Book { + + private int bookId; + private String title; + private boolean publicity; + private String color; + private String accountId; + + + public Book(String accountId, Integer bookId, String title, boolean publicity, String color, String time) { + this.accountId = accountId; + this.bookId = bookId; + this.title = title; + this.publicity = publicity; + this.color = color; + } + + //Setter + public void setTitle(String t) {title = t;} + public void setPublicity(boolean p) {publicity = p;} + public void setColor(String c) {color = c;} + public void setBookId(int id) {bookId = id;} + public void setAccountId(String a) {accountId = a;} + + //Getter + public String getTitle() {return title;} + public boolean getPublicity() {return publicity;} + public String getColor() {return color;} + public int getBookId() {return bookId;} + public String getAccountId() {return accountId;} } diff --git a/app/src/main/java/com/example/citrusclient/models/Todo.java b/app/src/main/java/com/example/citrusclient/models/Todo.java new file mode 100644 index 0000000..eb1d9a9 --- /dev/null +++ b/app/src/main/java/com/example/citrusclient/models/Todo.java @@ -0,0 +1,40 @@ +package com.example.citrusclient.models; + +public class Todo { + + String accountId; + Integer bookId; + String title; + boolean check; + int year; + int month; + int day; + Integer todoId; + + //セッター + public void setAccountId(String aid) {accountId = aid;} + public void setBookId(Integer bid) {bookId = bid;} + public void setTitle(String t) {title = t;} + public void setCheck(boolean c) {check = c;} + public void setYear(int y) {year = y;} + public void setMonth(int m) {month = m;} + public void setDay(int d) {day = d;} + public void setTodoId(Integer t) {todoId = t;} + + //ゲッター + public String getAccountId() {return accountId;} + public Integer getBookId(){return bookId;} + public String getTitle() {return title;} + + public boolean getCheck() {return check;} + + public int getYear() {return year;} + + public int getMonth() {return month;} + + public int getDay() {return day;} + + public Integer getTodoId() { + return todoId; + } +} diff --git a/app/src/main/java/com/example/citrusclient/rest/BooksRest.java b/app/src/main/java/com/example/citrusclient/rest/BooksRest.java index 53727ae..13cbfcd 100644 --- a/app/src/main/java/com/example/citrusclient/rest/BooksRest.java +++ b/app/src/main/java/com/example/citrusclient/rest/BooksRest.java @@ -1,7 +1,7 @@ package com.example.citrusclient.rest; -import java.util.Collection; -import java.util.HashMap; +import com.example.citrusclient.models.Book; + import retrofit2.Call; import retrofit2.Response; @@ -12,18 +12,84 @@ import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; +import retrofit2.http.Query; public interface BooksRest { + //本の一覧を返す @GET("accounts/{account_id}/books") - Call getBooks( - @Path("account_id") String account_id + Call getBooks( + @Path("account_id") String account_id, + @Query("token") String token ); + //本の新規作成 @FormUrlEncoded @POST("accounts/{account_id}/books") - Call createBook( - @Path("account_id") String account_id + Call createBook( + @Path("account_id") String account_id, + @Field("title") String title, + @Field("color") String color, + @Field("publicity") boolean publicity, + @Field("token") String token + ); + //本の情報を取得 + @GET("accounts/{account_id}/books/{book_id}") + Call getBook( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Query("token") String token + ); + + //本の削除 + @DELETE("accounts/{account_id}/books/{book_id}") + Call deleteBook( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Query("token") String token + ); + + //本のタイトルを返す(指定したbook_idの本のタイトルを返す) + @GET("accounts/{account_id}/books/{book_id}/title") + Call getTitle( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Query("token") String token + ); + + //本のタイトルを変更(指定したbook_idの本のタイトルを変更する) + @PUT("accounts/{account_id}/books/{book_id}/title") + Call putTitle( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Field("title") String title, + @Field("token") String token + ); + + //本の公開情報を返す(指定したbook_idの本の公開状態を返す) + @GET("accounts/{account_id}/books/{book_id}/public") + Call getPublicity( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Query("token") String token + ); + + //公開状態を変更する(指定された本の公開状態を変更する) + @PUT("accounts/{account_id}/books/{book_id}/public") + Call putPublicity( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Field("publicity") Boolean publicity, + @Field("token") String token + ); + + //本の色を変更する(book_idを指定して本の色を変更する) + @PUT("accounts/{account_id}/books/{book_id}/color") + Call putColor( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id, + @Field("color") String color, + @Field("token") String token ); } diff --git a/app/src/main/java/com/example/citrusclient/rest/TodosRest.java b/app/src/main/java/com/example/citrusclient/rest/TodosRest.java index 5e169ab..88c6ad8 100644 --- a/app/src/main/java/com/example/citrusclient/rest/TodosRest.java +++ b/app/src/main/java/com/example/citrusclient/rest/TodosRest.java @@ -1,5 +1,95 @@ package com.example.citrusclient.rest; +import com.example.citrusclient.models.Todo; + +import java.util.ArrayList; +import java.util.HashMap; + + +import retrofit2.Call; +import retrofit2.Response; +import retrofit2.http.DELETE; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Path; +import retrofit2.http.Query; + public interface TodosRest { + @GET("/accounts/{account_id}/books/{book_id}/todos") + Call> getAllTodos( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Query("token") String token + ); + + @GET("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}") + Call> getTodosByMonth( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Query("token") String token + ); + + @GET("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}") + Call> getTodosByDay( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Query("token") String token + ); + + @GET("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") + Call getTodoById( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Path("todo_id") Integer todoId, + @Query("token") String token + ); + + @FormUrlEncoded + @POST("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}") + Call createTodo( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Field("title") String title, + @Field("token") String token + ); + @FormUrlEncoded + @PUT("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}/check") + Call setCheck( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Path("todo_id") Integer todoId, + @Field("check") boolean check, + @Field("token") String token + ); + + @DELETE("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") + Call deleteTodoById( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Path("todo_id") Integer todoId, + @Query("token") String token + ); + + }