diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index fe0dea4..2e271cb 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -36,7 +36,8 @@ @Produces(MediaType.APPLICATION_JSON) public HashMap getBooks(@PathParam("account_id") String account_id, @QueryParam("token") String token){ - if(bookManager.getBooks(account_id) == null){ + HashMap books = bookManager.getBooks(account_id); + if(books == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -46,7 +47,7 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBooks(account_id); + return books; } } } @@ -57,7 +58,8 @@ @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 (bookManager.createBook(account_id, title, color, publicity) == null){ + Book book = bookManager.createBook(account_id, title, color, publicity); + if (book == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -80,7 +82,8 @@ @Produces(MediaType.APPLICATION_JSON) public Book getBook(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getBook(account_id, book_id) == null){ + Book book = bookManager.getBook(account_id, book_id); + if (book == null){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -90,7 +93,7 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBook(account_id, book_id); + return book; } } } @@ -101,7 +104,8 @@ @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(bookManager.deleteBook(account_id, book_id) == -1){ + int check = bookManager.deleteBook(account_id, book_id); + if(check == -1){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -123,7 +127,8 @@ @Produces(MediaType.TEXT_PLAIN) public String getTitle(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getTitle(account_id, book_id) == null) { + String str = bookManager.getTitle(account_id, book_id); + if (str == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -133,7 +138,7 @@ throw new WebApplicationException(response.build()); } else{ - return (bookManager.getTitle(account_id, book_id)); + return str; } } } @@ -145,7 +150,8 @@ @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(bookManager.putTitle(account_id, book_id, title) == -1){ + int check = bookManager.putTitle(account_id, book_id, title); + if(check == -1){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -167,7 +173,8 @@ @Produces(MediaType.TEXT_PLAIN) public Boolean getPublicity(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ - if (bookManager.getPublicity(account_id, book_id) == null) { + Boolean publicity = bookManager.getPublicity(account_id, book_id); + if (publicity == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -177,7 +184,7 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getPublicity(account_id, book_id); + return publicity; } } } @@ -188,7 +195,9 @@ @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(bookManager.putPublicity(account_id, book_id, publicity) == -1){ + + int check = bookManager.putPublicity(account_id, book_id, publicity); + if(check == -1){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); } @@ -209,7 +218,9 @@ @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(bookManager.putColor(account_id, book_id, color) == -1){ + + int check = bookManager.putColor(account_id, book_id, color); + if(check == -1){ var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); throw new WebApplicationException(response.build()); }