diff --git a/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java b/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java index 28428b3..f08a467 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java @@ -41,18 +41,33 @@ @PUT @Produces(MediaType.APPLICATION_FORM_URLENCODED) public void putFavorited(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("other_account_id") String other_account_id, @FormParam("token") String token){ + + //accountID存在確認 if(accountManager.getAccount(account_id) != null) { + //other_account_id存在確認 if(accountManager.getAccount(other_account_id) != null){ - if (accountManager.checkToken(other_account_id, token)) { - if (bookManager.getBook(account_id, book_id) != null) { + //book_id存在確認 + if (bookManager.getBook(account_id, book_id) != null) { + //token認証 + if (accountManager.checkToken(other_account_id, token)) { favoriteManager.putFavorited(account_id, book_id, other_account_id); favoriteManager.putFavorites(other_account_id, account_id, book_id);//変更点(要検討) } else { + //tokne認証失敗時のエラー表示 var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } + //本が存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("本が存在しません"); + throw new WebApplicationException(response.build()); } + //other_account_idが存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("accountが存在しません"); + throw new WebApplicationException(response.build()); } + //account_idが存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("accountが存在しません"); + throw new WebApplicationException(response.build()); } } @@ -61,18 +76,32 @@ @DELETE @Produces(MediaType.APPLICATION_FORM_URLENCODED) public void removeFavorited(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("other_account_id") String other_account_id, @QueryParam("token") String token){ + //account存在確認 if(accountManager.getAccount(account_id) != null){ + //other_account_id存在確認 if(accountManager.getAccount(other_account_id) != null){ - if(accountManager.checkToken(other_account_id,token)) { - if(bookManager.getBook(account_id,book_id) != null){ + //book_id存在確認 + if(bookManager.getBook(account_id,book_id) != null){ + //token承認 + if(accountManager.checkToken(other_account_id,token)) { favoriteManager.removeFavorited(account_id, book_id, other_account_id); favoriteManager.removeFavorites(other_account_id, account_id, book_id);//変更点(要検討) }else{ + //tokenが承認しないときに対するエラー表示 var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } + //本が存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("本が存在しません"); + throw new WebApplicationException(response.build()); } + //other_account_idが存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("accountが存在しません"); + throw new WebApplicationException(response.build()); } + //accountが存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("accountが存在しません"); + throw new WebApplicationException(response.build()); } } }