Newer
Older
CitrusServer / src / main / java / org / ntlab / citrusserver / resources / BooksRest.java
package org.ntlab.citrusserver.resources;

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.ntlab.citrusserver.entities.Book;
import org.ntlab.citrusserver.repositories.BookManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;


@Path("/accounts")
@Component


public class BooksRest {//BookRestはクラス

    private final BookManager bookManager;
    @Autowired //スプリングブートにいうサイン
    public BooksRest(BookManager bm){ //public クラス名()がコンストラクタ
        bookManager = bm;
    }


/// {account_id}/books
    private final HashMap<String, HashMap<Integer, Book>> books = new HashMap<>();

    /// その人の本のタイトルとかを返す
    @Path("/{account_id}/books")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public  HashMap<Integer, Book> getBooks(@PathParam("account_id") String account_id){
        return bookManager.getBooks(account_id);
    }

    @Path("/{account_id}/books")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時
    public int createBook(@PathParam("account_id") String account_id, @FormParam("title") String title, @FormParam("color") String color, @FormParam("publicity") Boolean publicity) {
        return bookManager.createBook(account_id, title, color, publicity);
    }


/// {account_id}/books/{book_id}
    @Path("/{account_id}/books/{book_id}")

  /// 本の情報を取得
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){
        return bookManager.getBook(account_id, book_id);
    }

///// /{account_id}/books/{book_id}/favorited
//    @Path("/{account_id}/books/{book_id}/favorited")
//
//  /// いいねしたアカウントを返す
//    @GET
//    @Produces(MediaType.APPLICATION_JSON)
//    public Book g(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){
//        Book book = bookManager.getBook(account_id, book_id);
//        return book;
//    }


/// /{account_id}/books/{book_id}/title
    @Path("/{account_id}/books/{book_id}/title")

  /// 本のタイトルを返す
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){
        return bookManager.getTitle(account_id, book_id);
    }

/// /accounts/{account_id}/books/{book_id}/public
    @Path("/{account_id}/books/{book_id}/public")

  /// 本の公開状態を返す
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){
        return bookManager.getPublicity(account_id, book_id);
    }







}