diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 49f2e4a..2695eb9 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -40,7 +40,7 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBooks(account_id, token); + return bookManager.getBooks(account_id); } } @@ -54,7 +54,7 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.createBook(account_id, title, color, publicity, token); + return bookManager.createBook(account_id, title, color, publicity); } } @@ -70,16 +70,23 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBook(account_id, book_id, token); + return bookManager.getBook(account_id, book_id); } } /// 本の削除 @Path("/{account_id}/books/{book_id}") @DELETE + @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void deleteTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if(!accountManager.checkToken(account_id, token)) return; - bookManager.deleteBook(account_id, book_id, token); + public String deleteTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + else{ + bookManager.deleteBook(account_id, book_id); + return "success"; + } } /// /{account_id}/books/{book_id}/title @@ -93,17 +100,24 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getTitle(account_id, book_id, token); + return bookManager.getTitle(account_id, book_id); } } /// 本のタイトル変更 @Path("/{account_id}/books/{book_id}/title") @PUT + @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void putTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("title") String title, @FormParam("token") String token){ - if(!accountManager.checkToken(account_id, token)) return; - bookManager.putTitle(account_id, book_id, title, token); + public String putTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("title") String title, @FormParam("token") String token){ + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + else{ + bookManager.putTitle(account_id, book_id, title); + return "success"; + } } /// /accounts/{account_id}/books/{book_id}/public @@ -117,17 +131,24 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getPublicity(account_id, book_id, token); + return bookManager.getPublicity(account_id, book_id); } } /// 公開情報を変更する @Path("/{account_id}/books/{book_id}/public") @PUT + @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void putPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("publicity") Boolean publicity, @FormParam("token") String token){ - if(!accountManager.checkToken(account_id, token)) return; - bookManager.putPublicity(account_id, book_id, publicity, token); + public String putPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("publicity") Boolean publicity, @FormParam("token") String token){ + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + else{ + bookManager.putPublicity(account_id, book_id, publicity); + return "success"; + } } /// /accounts/{account_id}/books/{book_id}/color @@ -135,8 +156,14 @@ @Path("/{account_id}/books/{book_id}/color") @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void putColor(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("color") String color, @FormParam("token") String token){ - if(!accountManager.checkToken(account_id, token)) return; - bookManager.putColor(account_id, book_id, color, token); + public String putColor(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @FormParam("color") String color, @FormParam("token") String token){ + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + else{ + bookManager.putColor(account_id, book_id, color); + return "success"; + } } } \ No newline at end of file