diff --git a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java
index af2a911..3f801b0 100644
--- a/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java
+++ b/src/main/java/org/ntlab/citrusserver/repositories/FavoriteManager.java
@@ -19,24 +19,31 @@
                     HashSet<String>>> //otheraccounts
             favoritedMap = new HashMap<>();
 
+    HashMap<String, //accountId
+            HashMap<String, //otherAccountId
+                    HashSet<Integer>>> //bookId
+            favoritesMap = new HashMap<>();
+
     //get
     //book_idをいいねしたaccount_idをリストとして返す
     public HashSet<String> getFavorited(String accountId, int bookId) {
-        if(accountManager.getAccount(accountId) == null) return null; //アカウントが存在しない
+        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の空のハッシュマップを用意
+        if (!favoritedMap.containsKey(accountId)) { //accountがなかったらbookidとotheraccountsの空のハッシュマップを用意
             favoritedMap.put(accountId, new HashMap<>());
         }
-        if(!favoritedMap.get(accountId).containsKey(bookId)) { //bookIdがなかったらotheraccountsの空のハッシュセットを用意
+        if (!favoritedMap.get(accountId).containsKey(bookId)) { //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) {
@@ -46,36 +53,55 @@
 
 
 
-    HashMap<String, HashMap<String , HashSet<Integer>>> favoritesMap = new HashMap<>();
-
 
     //いいねした本の一覧を返す
     public HashMap<String, HashSet<Integer>> getFavorites(String accountId) {
-        if(accountManager.getAccount(accountId) == null) return null;
+        if (accountManager.getAccount(accountId) == null) return null;
         return favoritesMap.get(accountId);
     }
 
     //取得したotherAccountIdのいいねした本を返す
     public HashSet<Integer> getFavoritesByID(String accountId, String otherAccountId) {
-        if(accountManager.getAccount(accountId) == null) return null;
-        if(!favoritesMap.get(accountId).containsKey(otherAccountId)) return null;
+        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)){
+        if (!favoritesMap.containsKey(accountId)) {
             favoritesMap.put(accountId, new HashMap<>());
         }
-        if(!favoritesMap.get(accountId).containsKey(otherAccountId)){
+        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);
     }
 
+    //アカウントが消去されたときに一緒に消す
+    public void removeFavoriteById(String accountId) {
+        for (String otherAccountId : favoritesMap.get(accountId).keySet()) {
+            for (Integer bookId : favoritesMap.get(accountId).get(otherAccountId)) {
+                favoritedMap.get(otherAccountId).get(bookId).remove(accountId);
+            }
+        }
+        favoritesMap.remove(accountId);
+    }
+
+    //本が消されたときに一緒に消す
+    public void removeFavoriteByBookID(String accountId, Integer bookId) {
+        for (String otherAccountId : favoritedMap.get(accountId).get(bookId)) {
+            favoritesMap.get(otherAccountId).get(accountId).remove(bookId);
+        }
+        favoritedMap.get(accountId).remove(bookId);
+    }
+
 }
+
+