diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java index 637c161..438bb14 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java @@ -1,7 +1,42 @@ 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; + @Repository public class FavoriteManager { + private final AccountManager accountManager; + + @Autowired + public FavoriteManager(AccountManager accountManager) { + this.accountManager = accountManager; + } + + private final HashMap>> //otheraccounts + favoritedMap = new HashMap<>(); + + + //book_idをいいねしたaccount_idをリストとして返す + public HashSet getFavorited(String accountId, int bookId) { + if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない + + return favoritedMap.get(accountId).get(bookId); + } + + //other_account_idの人がaccount_idのbook_idにいいねをした時 + public void putFavorited(String accountId, int bookId, String otherAccountId) { + favoritedMap.get(accountId).get(bookId).add(otherAccountId); + } + + //イイねしたaccount_idをイイねした人リストから削除 + public void removeFavorited(String accountId, int bookId, String otherAccountId) { + favoritedMap.get(accountId).get(bookId).remove(otherAccountId); + } + }