diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java index b3b0e12..509ff42 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java @@ -23,19 +23,26 @@ HashSet>> //otheraccounts favoritedMap = new HashMap<>(); - + //get //book_idをいいねしたaccount_idをリストとして返す public HashSet getFavorited(String accountId, int bookId) { if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない return favoritedMap.get(accountId).get(bookId); } - + //put //other_account_idの人がaccount_idのbook_idにいいねをした時 public void putFavorited(String accountId, int bookId, String otherAccountId) { + if(!favoritedMap.containsKey(accountId)) { //accountがなかったらbookidとotheraccountsの空のハッシュマップを用意 + favoritedMap.put(accountId, new HashMap<>()); + } + if(!favoritedMap.containsKey(bookId)) { //accountがなかったらbookidとotheraccountsの空のハッシュマップを用意 + favoritedMap.get(accountId).put(bookId, new HashSet<>()); + } + favoritedMap.get(accountId).get(bookId).add(otherAccountId); } - + //delete //イイねしたaccount_idをイイねした人リストから削除 public void removeFavorited(String accountId, int bookId, String otherAccountId) { favoritedMap.get(accountId).get(bookId).remove(otherAccountId);