Newer
Older
CitrusClient / app / src / main / java / com / example / citrusclient / rest / BooksRest.java
package com.example.citrusclient.rest;

import com.example.citrusclient.models.Book;


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 BooksRest {

    //本の一覧を返す
    @GET("accounts/{account_id}/books")
    Call<HashMap<Integer, Book>> getBooks(
            @Path("account_id") String account_id,
            @Query("token") String token
    );

    //本の新規作成
    @FormUrlEncoded
    @POST("accounts/{account_id}/books")
    Call<HashMap<Integer, Book>> 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<Book> 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<HashMap<Integer, Book>> 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<String> 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<String> 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<Boolean> 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<String> 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<String> putColor(
            @Path("account_id") String account_id,
            @Path("book_id") Integer book_id,
            @Field("color") String color,
            @Field("token") String token
    );

    @PUT("/{account_id}/books/{book_id}/favoriteCount")
    Call<String> registerFavoriteCount(
            @Path("account_id") String account_id,
            @Path("book_id") Integer book_id
    );

    @PUT("/{account_id}/books/{book_id}/favoriteCount")
    Call<String> unregisterFavoriteCount(
            @Path("account_id") String account_id,
            @Path("book_id") Integer book_id
    );
}