diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index b731b9e..fe0dea4 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -35,19 +35,19 @@ @GET @Produces(MediaType.APPLICATION_JSON) public HashMap getBooks(@PathParam("account_id") String account_id, @QueryParam("token") String token){ - if(!accountManager.checkToken(account_id, token)) { - var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + + if(bookManager.getBooks(account_id) == null){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if(bookManager.getBooks(account_id) == null){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ return bookManager.getBooks(account_id); } - } } @@ -56,16 +56,17 @@ @Produces(MediaType.APPLICATION_JSON) // intとかstringとかがたくさん返ってくるから、json public voidじゃないときは、返さなあかんから、 @Produces(MediaType.APPLICATION_JSON) これがいる @Consumes(MediaType.APPLICATION_FORM_URLENCODED) // postmanのbodyに入力する値がある時 public Book createBook(@PathParam("account_id") String account_id, @FormParam("title") String title, @FormParam("color") String color, @FormParam("publicity") Boolean publicity, @FormParam("token") String token) { - if(!accountManager.checkToken(account_id, token)) { - var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + + if (bookManager.createBook(account_id, title, color, publicity) == null){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if (bookManager.createBook(account_id, title, color, publicity) == null){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } - else{ + else { return bookManager.createBook(account_id, title, color, publicity); } } @@ -78,13 +79,14 @@ @GET @Produces(MediaType.APPLICATION_JSON) public Book getBook(@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("認証失敗"); + + if (bookManager.getBook(account_id, book_id) == null){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if (bookManager.getBook(account_id, book_id) == null){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -98,13 +100,14 @@ @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public String deleteBook(@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("認証失敗"); + + if(bookManager.deleteBook(account_id, book_id) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if(bookManager.deleteBook(account_id, book_id) == -1){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -119,13 +122,14 @@ @GET @Produces(MediaType.TEXT_PLAIN) public String getTitle(@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("認証失敗"); + + if (bookManager.getTitle(account_id, book_id) == null) { + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if (bookManager.getTitle(account_id, book_id) == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -140,13 +144,14 @@ @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 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("認証失敗"); + + if(bookManager.putTitle(account_id, book_id, title) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if(bookManager.putTitle(account_id, book_id, title) == -1){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -161,13 +166,14 @@ @GET @Produces(MediaType.TEXT_PLAIN) public Boolean getPublicity(@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("認証失敗"); + + if (bookManager.getPublicity(account_id, book_id) == null) { + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if (bookManager.getPublicity(account_id, book_id) == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -182,13 +188,13 @@ @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 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("認証失敗"); + if(bookManager.putPublicity(account_id, book_id, publicity) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if(bookManager.putPublicity(account_id, book_id, publicity) == -1){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{ @@ -203,13 +209,13 @@ @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 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("認証失敗"); + if(bookManager.putColor(account_id, book_id, color) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } else{ - if(bookManager.putColor(account_id, book_id, color) == -1){ - var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + if(!accountManager.checkToken(account_id, token)) { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } else{