diff --git a/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java b/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java index 69a50fe..1d03b33 100644 --- a/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java +++ b/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java @@ -3,6 +3,7 @@ import org.ntlab.nemophila.models.accounts.Account; import org.ntlab.nemophila.models.accounts.AccountManager; import org.ntlab.nemophila.models.accounts.Post; +import org.ntlab.nemophila.models.shops.Shop; import org.springframework.stereotype.Component; import javax.ws.rs.*; @@ -41,24 +42,32 @@ AccountManager am = AccountManager.getInstance(); Account account = am.getAccount(uid); - if (account.getToken().equals(token)) { - if (account != null) { - Post post = account.getPost(pid); - if (post != null) { - account.deletePost(pid); - } else { - var response = Response.status(Response.Status.NO_CONTENT); - response.status(404).entity("投稿が存在しません"); - throw new WebApplicationException(response.build()); - } - var response = Response.status(Response.Status.NO_CONTENT); - response.status(404).entity("アカウントが存在しません"); - throw new WebApplicationException(response.build()); - } - } else { + //tokenが不一致の時 + if (!account.getToken().equals(token)) { var response = Response.status(Response.Status.NO_CONTENT); response.status(401).entity("tokenの認証に失敗"); throw new WebApplicationException(response.build()); } + + //アカウントが存在しないとき + if (account == null) { + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("アカウントが存在しません"); + throw new WebApplicationException(response.build()); + } + + //投稿が存在しないとき + Post post = account.getPost(pid); + if (post == null) { + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("投稿が存在しません"); + throw new WebApplicationException(response.build()); + } + + //正しい動作 + account.deletePost(pid); + Shop shop = post.getShop(); + shop.deletePost(post); + } }