diff --git a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java index 4278aac..3de0d2a 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/AccountManager.java @@ -3,6 +3,7 @@ import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.resources.AccountsRest; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; @@ -13,17 +14,22 @@ @Repository public class AccountManager { + private final AccountsRest accountsRest; private HashMap accounts = new HashMap(); //keyにaccountId,valueにaccount private HashMap accountToken = new HashMap<>(); //keyがaccountId,valueがtoken + public AccountManager(AccountsRest accountsRest) { + this.accountsRest = accountsRest; + } + // アカウントの一覧をリストとして返す(GET) public Set getAccountsID() { return accounts.keySet(); } // account_idとpasswordを設定し新しいアカウントを作成する(POST) - public String newAccount(String accountId, String password) { + public String createAccount(String accountId, String password) { UUID str = UUID.randomUUID(); String token = str.toString(); Account account = new Account(accountId, password); @@ -34,6 +40,11 @@ return token; } + //tokenを返す (accountIdとtokenを比較してtrueかfalseを返すように変更) + public String createToken(String accountId) { + return accountToken.get(accountId); + } + // 指定されたアカウントの情報を返す(GET) public Account getAccount(String accountId) { return accounts.get(accountId); @@ -41,7 +52,18 @@ // アカウント情報を全削除する(DELETE) public void deleteAccount(String accountId, String password, String token) { + if(accountToken.get(accountId).equals(token)) { + if(accounts.get(accountId).getPassword().equals(password)) { + accounts.remove(accountId); + } + } + } + // 指定されたIDのパスワードを変更する (PUT) + public void changePassword(String accountId, String token, String oldPassword, String newPassword) { + if(accountToken.get(accountId).equals(token)) { + + } } // 指定されたIDの自己紹介を返す(GET) @@ -49,38 +71,33 @@ return accounts.get(accountId).getIntroduction(); } + // 指定されたIDの自己紹介を変更する (PUT) + public void newintroduction(String accountId, String token, String introduction) { + + } + // 指定されたIDのお気に入りの本のリストを返す(GET) - public ArrayList> favoriteBook(String accountId, String token) { + public ArrayList> Favorites(String accountId, String token) { return null; } // 指定されたIDのお気に入りの本のリストを返す(指定した人物) (GET) - public ArrayList FavoriteBook(String accountId, String otherAccountId, String token) { + public ArrayList FavoritesBookId(String accountId, String otherAccountId, String token) { return null; } - // 指定されたIDのアカウントを変更する (PUT) - public void newpassword() { - - } - - // 指定されたIDの自己紹介を変更する (PUT) - public void newintro() { - - } - - // お気に入りにの本のbook_idを削除する (DELETE) - public void deletefavbook() { + // お気に入りの本のbook_idを削除する (DELETE) + public void deletefavbookid(String accountId, String token, String otherAccountId, Integer bookId) { } // いいねした本のアカウントIDとbook_idを追加する(いいねした側に追加) (PUT) - public void putfavoriteid() { + public void putfavoriteid(String accountId, String token, String otherAccountId, Integer bookId) { } // アカウントidとパスワードでログインし、tokenを返す (POST) - public void login() { - + public String login(String accountId, String password) { + return accountToken.get(accountId); } }