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.ArrayList;
import java.util.HashMap;
import java.util.Set;
@Path("/accounts")
@Component //accountRestのインスタンスを一個作る
public class AccountsRest {
private final AccountManager accountManager; //finalは書き換えられない
@Autowired//springbootの決まり
public AccountsRest(AccountManager am) {
accountManager = am;
}
// アカウントの一覧をリストとして返す(GET)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Set<String> getAccount(){
return accountManager.getAccountsID();
}
// account_idとpasswordを設定し新しいアカウントを作成する(POST)
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)//bodyに入力する値がある時
public String signup(@FormParam("account_id") String accountId, @FormParam("password") String password) {
String token;
token = accountManager.createAccount(accountId, password);
return token;
}
//////////
@Path("/{account_id}")
// 指定されたアカウントの情報を返す(GET)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Account getAccountInfo(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる
Account ac = accountManager.getAccount(accountId);
return ac;
}
// アカウント情報を全削除する(DELETE)
// @DELETE
// @Path("/{account_id}/password")
// //指定されたIDのパスワードを変更する (PUT)
// @PUT
// public void changePassword(@PathParam("account_id") String accountId,
// @QueryParam("token") String token,
// @PathParam("old_password")String oldPassword,
// @PathParam("new_password")String newPassword){ //account_idを渡してManegerから値が返ってくる
// return accountManager.changePassword(accountId,token,oldPassword,newPassword);
//
// }
/////////
@Path("/accounts/{account_id}/introduction")
// 指定されたIDの自己紹介を返す(GET)
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getIntroduction(@PathParam("account_id") String accountId){ //account_idを渡してintroductionが返ってくる
String ac = accountManager.AccountIntro(accountId);
return ac;
}
// 指定されたIDの自己紹介を変更する (PUT)
// @PUT
/////////
// @Path("/accounts/{account_id}/photo")
// //画像を返す
// @GET
// public String getAccount(@PathParam("account_id") String accountId){ //account_idを渡してManegerから値が返ってくる
// Account ac = accountManager.getAccount(accountId);
// return ac.getPhoto();
// }
//
// @PUT
/////////
@Path("/accounts/{account_id}/favorites")
//指定されたIDのお気に入りの本のリストを返す
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<HashMap<String, String>> favoriteBook(@PathParam("account_id") String accountId, @QueryParam("token")String token){
return accountManager.Favorites(accountId,token);
}
////////
@Path("/accounts/{account_id}/favorites/{other_account_id}")
//指定されたIDのお気に入りの本のリストを返す(指定した人物)
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Integer> FavoriteBook(@PathParam("account_id") String accountId,@PathParam("other_account_id") String otherAccountId,@QueryParam("token")String token){ //account_idを渡してManegerから値が返ってくる
return accountManager.FavoritesBookId(accountId,otherAccountId,token);
}
//////////
// @Path("/accounts/{account_id}/favorites/{other_account_id}/{book_id}")
// お気に入りの本のbook_idを削除する (DELETE)
// @DELETE
// いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT)
// @PUT
////////
// アカウントidとパスワードでログインし、tokenを返す (POST)
// @Path("/accounts/{account_id}/login")
// @POST
// @Consumes(MediaType.APPLICATION_JSON)
// public void login(@PathParam("account_id") String accountId,@FormParam("password") String password) {
// accountManager.put(accountId, password);
// }
}