diff --git a/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java index 92493a7..99df9e9 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/PublicBooksRest.java @@ -3,6 +3,8 @@ import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import org.ntlab.citrusserver.entities.Book; +import org.ntlab.citrusserver.repositories.PublicBookManager; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @@ -12,36 +14,65 @@ @Component public class PublicBooksRest { + private final PublicBookManager publicBookManager; + @Autowired + public PublicBooksRest(PublicBookManager pbm) { + publicBookManager = pbm; + } + //公開されている本の一覧を返す @GET @Produces(MediaType.APPLICATION_JSON) public ArrayList getAllPublicBooks() { - return null; + return publicBookManager.getAllPublicBooks(); } - //検索条件を指定して本を検索(タイトル ソート可能) +// //検索条件を指定して本を検索(タイトル) +// @Path("/search") +// @GET +// @Produces(MediaType.APPLICATION_JSON) +// public ArrayList searchBooksByTitle(@QueryParam("search_title") String search_title) { +// return publicBookManager.searchBooksByTitle(search_title); +// } + +// //検索条件を指定して本を検索(タイトル ソート可能) +// @Path("/search") +// @GET +// @Produces(MediaType.APPLICATION_JSON) +// public ArrayList searchBooksByTitle(@QueryParam("search_title") String search_title, @QueryParam("sort_by") Integer sort_by) { +// return publicBookManager.searchBooksByTitle(search_title, sort_by); +// } +// +// //検索条件を指定して本を検索(アカウント) +// @Path("/search") +// @GET +// @Produces(MediaType.APPLICATION_JSON) +// public ArrayList searchBooksByAccount(@QueryParam("search_account_id") String search_account_id) { +// return publicBookManager.searchBooksByAccount(search_account_id); +// } +// +// //検索条件を指定して本を検索(アカウント ソート可能) +// @Path("/search") +// @GET +// @Produces(MediaType.APPLICATION_JSON) +// public ArrayList searchBooksByAccount(@QueryParam("search_account_id") String search_account_id, @QueryParam("sort_by") int sort_by) { +// return publicBookManager.searchBooksByAccount(search_account_id, sort_by); +// } + + //検索条件を指定して本を検索(アカウントとタイトル) @Path("/search") @GET @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public ArrayList searchBooksByTitle(@FormParam("search_title") String search_title, @FormParam("sort_by") int sort_by) { - return null; - } - - //検索条件を指定して本を検索(アカウント ソート可能) - @GET - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public ArrayList searchBooksByAccount(@FormParam("search_account_id") String search_account_id, @FormParam("sort_by") int sort_by) { - return null; - } - - //検索条件を指定して本を検索(アカウントとタイトル) - @GET - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public ArrayList searchBooksByTitleAndAccount(@FormParam("search_title") String search_title, @FormParam("search_account_id") String search_account_id) { - return null; + public ArrayList searchBooksByTitleAndAccount(@QueryParam("search_title") String search_title, @QueryParam("search_account_id") String search_account_id) { + if(!search_title.isEmpty() && !search_account_id.isEmpty()) { + return publicBookManager.searchBooksByTitleAndAccount(search_title, search_account_id); + } else if(!search_title.isEmpty()) { + return publicBookManager.searchBooksByTitle(search_title); + } else if(!search_account_id.isEmpty()) { + return publicBookManager.searchBooksByAccount(search_account_id); + } else { + return publicBookManager.getAllPublicBooks(); + } } }