diff --git a/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java b/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java index f816691..9a96b4e 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/FavoritedRest.java @@ -48,19 +48,26 @@ if (accountManager.getAccount(other_account_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("認証失敗"); + //本の公開状況確認 + if(bookManager.getPublicity(account_id, book_id)){ + //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 { + //token認証失敗時のエラー表示 + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + }else{ + //本が公開されていないときのエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("本が公開されていません"); throw new WebApplicationException(response.build()); } } else { - //本が存在しない時に対するエラー表示 - var response = Response.status(Response.Status.NOT_FOUND).entity("本が存在しません"); - throw new WebApplicationException(response.build()); + //本が存在しない時に対するエラー表示 + var response = Response.status(Response.Status.NOT_FOUND).entity("本が存在しません"); + throw new WebApplicationException(response.build()); } } else { //other_account_idが存在しない時に対するエラー表示 @@ -84,13 +91,20 @@ if (accountManager.getAccount(other_account_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("認証失敗"); + //本の公開状況確認 + if(bookManager.getPublicity(account_id, book_id)) { + //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()); + } + }else{ + //本が公開していないときに対するエラー + var response = Response.status(Response.Status.NOT_FOUND).entity("本が公開されていません"); throw new WebApplicationException(response.build()); } } else {