diff --git a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java index 550e06a..cb143f2 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java @@ -31,8 +31,11 @@ private final AccountManager accountManager; - public TodoManager(AccountManager accountManager) { + private final BookManager bookManager; + + public TodoManager(AccountManager accountManager, BookManager bookManager) { this.accountManager = accountManager; + this.bookManager = bookManager; } /** @@ -69,15 +72,16 @@ * @return そのアカウントの本に所属するtodoのうち、指定した年月のtodoを返します */ public HashMap> getTodosByMonth(String accountId, int bookId, int year, int month, String token){ + if(!accountManager.checkToken(accountId, token)){ + return null; + } + if(!todos.get(accountId).get(bookId).containsKey(year)){ return new HashMap>(); } if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ return new HashMap>(); } - if(!accountManager.checkToken(accountId, token)){ - return null; - } return todos.get(accountId).get(bookId).get(year).get(month); } @@ -189,6 +193,9 @@ if(!accountManager.checkToken(accountId, token)){ return -1; } + if(!bookManager.getBooks(accountId).containsKey(bookId)){ + return -1; + } if(!todos.containsKey(accountId)){ todos.put(accountId, new HashMap<>()); } @@ -245,6 +252,24 @@ if(!accountManager.checkToken(accountId, token)){ return; } + if(!todos.containsKey(accountId)){ + return; + } + if(!todos.get(accountId).containsKey(bookId)){ + return; + } + if(!todos.get(accountId).get(bookId).containsKey(year)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).get(month).get(day).containsKey(todoId)){ + return; + } todos.get(accountId).get(bookId).get(year).get(month).get(day).remove(todoId); } @@ -276,6 +301,27 @@ if(!accountManager.checkToken(accountId, token)){ return; } + if(!accountManager.checkToken(accountId, token)){ + return; + } + if(!todos.containsKey(accountId)){ + return; + } + if(!todos.get(accountId).containsKey(bookId)){ + return; + } + if(!todos.get(accountId).get(bookId).containsKey(year)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ + return; + } + if(!todos.get(accountId).get(bookId).get(year).get(month).get(day).containsKey(todoId)){ + return; + } todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setCheck(check); }