diff --git a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java index 2695eb9..934dc2d 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/BooksRest.java @@ -40,7 +40,14 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBooks(account_id); + if(bookManager.getBooks(account_id) == null){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return bookManager.getBooks(account_id); + } + } } @@ -70,7 +77,13 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getBook(account_id, book_id); + if (bookManager.getBook(account_id, book_id) == null){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return bookManager.getBook(account_id, book_id); + } } } /// 本の削除 @@ -78,14 +91,19 @@ @DELETE @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public String deleteTodoById(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token){ + 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("認証失敗"); throw new WebApplicationException(response.build()); } else{ - bookManager.deleteBook(account_id, book_id); - return "success"; + if(bookManager.deleteBook(account_id, book_id) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return "success"; + } } } @@ -100,7 +118,13 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getTitle(account_id, book_id); + if (bookManager.getTitle(account_id, book_id) == null) { + var response = Response.status(Response.Status.FORBIDDEN).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return (bookManager.getTitle(account_id, book_id)); + } } } @@ -115,8 +139,13 @@ throw new WebApplicationException(response.build()); } else{ - bookManager.putTitle(account_id, book_id, title); - return "success"; + if(bookManager.putTitle(account_id, book_id, title) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return "success"; + } } } @@ -131,7 +160,13 @@ throw new WebApplicationException(response.build()); } else{ - return bookManager.getPublicity(account_id, book_id); + if (bookManager.getPublicity(account_id, book_id) == null) { + var response = Response.status(Response.Status.FORBIDDEN).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return bookManager.getPublicity(account_id, book_id); + } } } @@ -146,8 +181,13 @@ throw new WebApplicationException(response.build()); } else{ - bookManager.putPublicity(account_id, book_id, publicity); - return "success"; + if(bookManager.putPublicity(account_id, book_id, publicity) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return "success"; + } } } @@ -162,8 +202,13 @@ throw new WebApplicationException(response.build()); } else{ - bookManager.putColor(account_id, book_id, color); - return "success"; + if(bookManager.putColor(account_id, book_id, color) == -1){ + var response = Response.status(Response.Status.NOT_FOUND).entity("アカウントが見つかりません"); + throw new WebApplicationException(response.build()); + } + else{ + return "success"; + } } } } \ No newline at end of file