diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java index 438bb14..b3b0e12 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java @@ -1,12 +1,14 @@ package org.ntlab.citrusserver.repositories; - -import org.ntlab.citrusserver.entities.Book; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.HashMap; import java.util.HashSet; + +import java.util.HashMap; +import java.util.HashSet; + @Repository public class FavoriteManager { private final AccountManager accountManager; @@ -39,4 +41,39 @@ favoritedMap.get(accountId).get(bookId).remove(otherAccountId); } + + + + HashMap>> favoritesMap = new HashMap(); + + + //いいねした本の一覧を返す + public HashMap> getFavorites(String accountId) { + if(accountManager.getAccount(accountId) == null) return null; + return favoritesMap.get(accountId); + } + + //取得したotherAccountIdのいいねした本を返す + public HashSet getFavoritesByID(String accountId, String otherAccountId) { + if(accountManager.getAccount(accountId) == null) return null; + if(!favoritesMap.get(accountId).containsKey(otherAccountId)) return null; + return favoritesMap.get(accountId).get(otherAccountId); + } + + //いいねした本を追加する + public void putFavorites(String accountId, String otherAccountId, Integer bookId) { + if(!favoritesMap.containsKey(accountId)){ + favoritesMap.put(accountId, new HashMap<>()); + } + if(!favoritesMap.get(accountId).containsKey(otherAccountId)){ + favoritesMap.get(accountId).put(otherAccountId, new HashSet<>()); + } + favoritesMap.get(accountId).get(otherAccountId).add(bookId); + + } + //いいねした本を消去する + public void removeFavorites(String accountId, String otherAccountId, Integer bookId) { + favoritesMap.get(accountId).get(otherAccountId).remove(bookId); + } + }