diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index 34687a5..c6d54d3 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -1,17 +1,108 @@ package org.ntlab.citrusserver.resources; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; +import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.repositories.AccountManager; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - +import java.util.HashMap; +import java.util.Set; @Path("/accounts") -@Component +@Component //accountRestのインスタンスを一個作る public class AccountsRest { - @GET - @Produces(MediaType.TEXT_PLAIN) - public String getMessage() { - return null; + private final AccountManager accountManager; //finalは書き換えられない + @Autowired//springbootの決まり + public AccountsRest(AccountManager am) { + accountManager = am; + } +///accountの一覧を返す + private HashMap accounts = new HashMap<>(); + @GET + @Produces(MediaType.APPLICATION_JSON) + public Set getAccount(){ + return accounts.keySet(); + } + + +//accountの新規作成 + @POST + @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時 + public void signup(@FormParam("account_id") String account_id, @FormParam("password") String password) { + accounts.put(account_id, password); + } + +////////// + @Path("/{account_id}") + +//account_idの情報を返す”introduction”と[本] + @GET + public Account getAccount(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる + Account ac = accountManager.getAccount(accountId); + return ac; + } + + @DELETE + + +/////// + @Path("/{account_id}/password") +// + @PUT + + +/////// + @Path("/accounts/{account_id}/introduction") +//自己紹介を返す + @GET + public String getAccount(@PathParam("account_id") String account_id){ //account_idを渡してintroductionが返ってくる + Account ac = accountManager.getAccount(account_id); + return ac.getIntroduction(); + } + + @PUT + +///////// + @Path("/accounts/{account_id}/photo") +//画像を返す + @GET + public String getAccount(@PathParam("account_id") String account_id){ //account_idを渡してManegerから値が返ってくる + Account ac = accountManager.getAccount(account_id); + return ac.getPhoto(); + } + + @PUT + +///////// + @Path("/accounts/{account_id}/favorites") +//お気に入りの本のリストを返す + @GET + public String getAccount(@PathParam("account_id") String account_id,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる + Account ac = accountManager.getAccount(account_id,token); + return ac.getFavorites(); + } + + +//////// + @Path("/accounts/{account_id}/favorites/{other_account_id}") +//お気に入りの本のリストを返す + @GET + public String getAccount(@PathParam("account_id") String account_id,@PathParam("other_account_id") String other_account_id,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる + Account ac = accountManager.getAccount(account_id,other_account_id,token); + return ac.getFavoritesBookId(); + } + +//////// + @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}") + @DELETE + @PUT +//////// + @Path("/accounts/{account_id}/login") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void login(@PathParam("account_id") String account_id),@FormParam("password") String password) { + accounts.put(account_id, password); } }