diff --git a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java index 398af31..5dc5ccf 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/TodoRest.java @@ -4,6 +4,7 @@ import jakarta.ws.rs.core.MediaType; import org.apache.coyote.http11.upgrade.UpgradeServletOutputStream; import org.ntlab.citrusserver.entities.Todo; +import org.ntlab.citrusserver.repositories.AccountManager; import org.ntlab.citrusserver.repositories.TodoManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -15,12 +16,14 @@ public class TodoRest { private final TodoManager todoManager; + private final AccountManager accountManager; @Autowired - public TodoRest(TodoManager tm, TodoManager todoManager) { + public TodoRest(TodoManager todoManager, AccountManager accountManager) { this.todoManager = todoManager; - todoManager = tm; + this.accountManager = accountManager; } + //test用 @Path("/TodoTest") @GET @@ -35,8 +38,10 @@ @GET @Produces(MediaType.APPLICATION_JSON) public HashMap>>> getAllTodos(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token) { - return todoManager.getAllTodos(account_id, book_id, token); - + if(accountManager.checkToken(account_id,token)==true){ + return todoManager.getAllTodos(account_id, book_id, token); + } + return null; } //指定された本の指定された年と月のtodoをすべて返す @@ -44,7 +49,10 @@ @GET @Produces(MediaType.APPLICATION_JSON) public HashMap> getTodosByMonth(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @QueryParam("token") String token) { - return todoManager.getTodosByMonth(account_id, book_id, year, month,token); + if(accountManager.checkToken(account_id,token)==true) { + return todoManager.getTodosByMonth(account_id, book_id, year, month, token); + } + return null; } //指定された本の指定された年と月と日のtodoをすべて返す @@ -52,8 +60,10 @@ @GET @Produces(MediaType.APPLICATION_JSON) public HashMap getTodosByDay(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) { - return todoManager.getTodosByDay(account_id, book_id, year, month, day, token); - + if(accountManager.checkToken(account_id,token)==true) { + return todoManager.getTodosByDay(account_id, book_id, year, month, day, token); + } + return null; } //本のtodoを年月日とtodo_idを指定してtodoを一つ返す @@ -61,8 +71,11 @@ @GET @Produces(MediaType.APPLICATION_JSON) public Todo getTodoById(@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, @QueryParam("token") String token) { - Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id, token); - return todo; + if(accountManager.checkToken(account_id,token)==true) { + Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id, token); + return todo; + } + return null; } @@ -72,7 +85,10 @@ @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Todo createTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @FormParam("title") String title,@FormParam("token") String token) { - return todoManager.createTodo(account_id, book_id, year, month, day, title,token); + if(accountManager.checkToken(account_id,token)==true) { + return todoManager.createTodo(account_id, book_id, year, month, day, title, token); + } + return null; } //todoを選んで達成状態を変更する @@ -81,19 +97,23 @@ @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}/check") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void setCheck(@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("check") boolean check, @FormParam("token") String token){ - todoManager.setCheck(account_id, book_id, year, month, day, todo_id,check,token); + if(accountManager.checkToken(account_id,token)==true) { + todoManager.setCheck(account_id, book_id, year, month, day, todo_id, check, token); + } } + //本のtodoを年月日とtodo_idを指定してそのtodoを削除する @DELETE @Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void deleteTodoById(@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, @QueryParam("token") String token){ - todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id,token); + if(accountManager.checkToken(account_id,token)==true) { + todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id, token); + } } - } \ No newline at end of file