diff --git a/src/main/java/org/ntlab/citrusserver/entities/Book.java b/src/main/java/org/ntlab/citrusserver/entities/Book.java index c68c40e..08a7d4b 100644 --- a/src/main/java/org/ntlab/citrusserver/entities/Book.java +++ b/src/main/java/org/ntlab/citrusserver/entities/Book.java @@ -8,6 +8,7 @@ private String color; private String accountId; private String time; + private int favoriteCount; public Book(String accountId, Integer bookId, String title, boolean publicity, String color, String time) { @@ -19,6 +20,7 @@ this.color = color; this.time = time; + this.favoriteCount = 0; } @@ -34,4 +36,6 @@ public String getAccountId() {return accountId;} public void setTime(String t) {time = t;} public String getTime() {return time;} + public void setFavoritedCount(int f) {favoriteCount = f;} + public int getFavoritedCount() {return favoriteCount;} } diff --git a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java index 5b0012e..d8ca937 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/BookManager.java @@ -121,6 +121,16 @@ booksMap.get(accountId).get(bookId).setColor(color); } + public void registerFavoriteCount(String accountId, Integer bookId){ + int favoriteCount = booksMap.get(accountId).get(bookId).getFavoritedCount(); + booksMap.get(accountId).get(bookId).setFavoritedCount(favoriteCount + 1); + } + + public void unregisterFavoriteCount(String accountId, Integer bookId){ + int favoriteCount = booksMap.get(accountId).get(bookId).getFavoritedCount(); + booksMap.get(accountId).get(bookId).setFavoritedCount(favoriteCount - 1); + } + @Override public void accountDeleted(Account account) { if(!booksMap.containsKey(account.getId())) return; diff --git a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java index cd40e22..4595917 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java @@ -338,6 +338,33 @@ return 1; } + public int setTodo(String accountId, int bookId, int year, int month, int day, int todoId, String title){ + if(!todos.containsKey(accountId)){ + return -1; + } + if(!todos.get(accountId).containsKey(bookId)){ + 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 -1; + } + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setTitle(title); + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setBookId(bookId); + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setYear(year); + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setMonth(month); + todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setDay(day); + return 1; + } + /** *todo_idを指定してtodoの達成状態を変更 * diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 02dd8f3..5dcacc7 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -147,6 +147,26 @@ return "success"; } + @Path("/{account_id}/books/{book_id}/favoriteCount") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String registerFavoriteCount(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ + + accountCheck(account_id); + bookManager.registerFavoriteCount(account_id, book_id); + return "success"; + } + + @Path("/{account_id}/books/{book_id}/favoriteCount") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String unregisterFavoriteCount(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id){ + + accountCheck(account_id); + bookManager.unregisterFavoriteCount(account_id, book_id); + return "success"; + } + ///--------------------------------------------------------------------- ///private ///--------------------------------------------------------------------- diff --git a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java index 50bdee9..b435fc2 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java @@ -9,6 +9,7 @@ import org.ntlab.citrusserver.repositories.BookManager; import org.ntlab.citrusserver.repositories.TodoManager; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CachePut; import org.springframework.stereotype.Component; import java.util.HashMap; @@ -113,6 +114,24 @@ } } + @PUT + @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + @Produces(MediaType.APPLICATION_JSON) + public void setTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, @PathParam("todo_id") Integer todo_id, @FormParam("title") String title, + @FormParam("new_year") Integer new_year,@FormParam("new_month") Integer new_month,@FormParam("new_day") Integer new_day, @FormParam("token") String token){ + if (accountManager.checkToken(account_id, token)) { + if (todoManager.setTodo(account_id, book_id, new_year, new_month, new_day, todo_id, title) == -1) { + var response = Response.status(Response.Status.BAD_REQUEST).entity("変更失敗"); + throw new WebApplicationException(response.build()); + } + }else{ + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } + /* //本のtodoを年月日とtodo_idを指定してそのtodoを削除する @DELETE