diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java index 1d95766..9452ca7 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java @@ -1,4 +1,6 @@ package org.ntlab.citrusserver.repositories; +import org.ntlab.citrusserver.entities.Account; +import org.ntlab.citrusserver.entities.Book; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -6,12 +8,15 @@ import java.util.HashSet; @Repository -public class FavoriteManager { +public class FavoriteManager implements IAccountListener, IBookListener { private final AccountManager accountManager; @Autowired - public FavoriteManager(AccountManager accountManager) { + public FavoriteManager(AccountManager accountManager, BookManager bookManager) { this.accountManager = accountManager; + this.accountManager.addListener(this); + bookManager.addListener(this); + } //favorited @@ -130,6 +135,24 @@ } favoritedMap.get(accountId).remove(bookId); // tedのbookIdを消したいとき } + + @Override + public void accountDeleted(Account account) { + removeFavoriteById(account.getId()); + } + + + @Override + public void bookChanged(Account account, Book book) { + + } + + @Override + public void bookDeleted(Account account, Book book) { + removeFavoriteByBookID(account.getId(), book.getBookId()); + } + + }