| |
---|
| | * アカウントの本の次に与えるべきtodoのidを管理します |
---|
| | */ |
---|
| | private final HashMap<String, Integer> nextTodoId = new HashMap<>(); |
---|
| | |
---|
| | private final AccountManager accountManager; |
---|
| | |
---|
| | private final BookManager bookManager; |
---|
| | |
---|
| | public TodoManager(AccountManager accountManager, BookManager bookManager) { |
---|
| | this.accountManager = accountManager; |
---|
| | public TodoManager(BookManager bookManager) { |
---|
| | this.bookManager = bookManager; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| |
---|
| | * } |
---|
| | */ |
---|
| | public HashMap<Integer, HashMap<Integer, HashMap<Integer, HashMap<Integer, Todo>>>> |
---|
| | getAllTodos(String accountId, int bookId, String token){ |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return null; |
---|
| | } |
---|
| | return todos.get(accountId).get(bookId); |
---|
| | } |
---|
| |
---|
| | * @param month 月 |
---|
| | * @return そのアカウントの本に所属するtodoのうち、指定した年月のtodoを返します |
---|
| | */ |
---|
| | public HashMap<Integer, HashMap<Integer, Todo>> 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<Integer, HashMap<Integer, Todo>>(); |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return new HashMap<Integer, HashMap<Integer, Todo>>(); |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).containsKey(year)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return null; |
---|
| | } |
---|
| | return todos.get(accountId).get(bookId).get(year).get(month); |
---|
| | } |
---|
| | |
---|
| |
---|
| | * @return そのアカウントの本に所属するtodoのうち、指定した年月日のtodoを返します |
---|
| | */ |
---|
| | public HashMap<Integer, Todo> getTodosByDay(String accountId, int bookId, int year, int month, int day, String token){ |
---|
| | if(!todos.get(accountId).get(bookId).containsKey(year)){ |
---|
| | return new HashMap<Integer, Todo>(); |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return new HashMap<Integer, Todo>(); |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ |
---|
| | return new HashMap<Integer, Todo>(); |
---|
| | } |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ |
---|
| | return null; |
---|
| | } |
---|
| | return todos.get(accountId).get(bookId).get(year).get(month).get(day); |
---|
| | } |
---|
| |
---|
| | * @param todoId todoのid |
---|
| | * @return idを指定してtodoを返す |
---|
| | */ |
---|
| | public Todo getTodoById(String accountId, int bookId, int year, int month, int day, int todoId, String token){ |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).containsKey(bookId)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).containsKey(year)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ |
---|
| | return null; |
---|
| | } |
---|
| | return todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId); |
---|
| | } |
---|
| |
---|
| | * @param title 追加するべきtodoのタイトル |
---|
| | * @return 新しいtodoのid |
---|
| | */ |
---|
| | public Todo createTodo(String accountId, int bookId, int year, int month, int day, String title, String token){ |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!bookManager.getBooks(accountId, token).containsKey(bookId)){ |
---|
| | if(bookManager.getBooks(accountId, token) == null){ |
---|
| | return null; |
---|
| | } |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | todos.put(accountId, new HashMap<>()); |
---|
| |
---|
| | * @param accountId アカウントのid |
---|
| | * @param bookId 本のid |
---|
| | * @param todoId 削除したいtodoのid |
---|
| | */ |
---|
| | public void deleteTodoById(String accountId, int bookId, int year, int month, int day, int todoId, String token){ |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | return; |
---|
| | } |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return; |
---|
| | public int deleteTodoById(String accountId, int bookId, int year, int month, int day, int todoId, String token){ |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return -1; |
---|
| | } |
---|
| | 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; |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).containsKey(year)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).get(day).containsKey(todoId)){ |
---|
| | return; |
---|
| | return -1; |
---|
| | } |
---|
| | todos.get(accountId).get(bookId).get(year).get(month).get(day).remove(todoId); |
---|
| | return 1; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | *idを指定してtodoを削除 |
---|
| |
---|
| | * @param bookId 本のid |
---|
| | * @param todoId 変更したいtodoのid |
---|
| | * @param check 変更後の達成状態 |
---|
| | */ |
---|
| | public void setCheck(String accountId, int bookId, int year, int month, int day, int todoId, boolean check, String token){ |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | return; |
---|
| | } |
---|
| | if(!accountManager.checkToken(accountId, token)){ |
---|
| | return; |
---|
| | } |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return; |
---|
| | public int setCheck(String accountId, int bookId, int year, int month, int day, int todoId, boolean check, String token){ |
---|
| | if(!todos.containsKey(accountId)){ |
---|
| | return -1; |
---|
| | } |
---|
| | 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; |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).containsKey(year)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){ |
---|
| | return -1; |
---|
| | } |
---|
| | if(!todos.get(accountId).get(bookId).get(year).get(month).get(day).containsKey(todoId)){ |
---|
| | return; |
---|
| | return -1; |
---|
| | } |
---|
| | todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setCheck(check); |
---|
| | return 1; |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | *todo_idを指定してtodoの達成状態を変更 |
---|
| |
---|
| | |