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 64ced8c..c1fea72 100644 --- a/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java +++ b/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java @@ -1,26 +1,52 @@ package org.ntlab.nemophila.resources.accounts; +import org.ntlab.nemophila.models.accounts.Account; +import org.ntlab.nemophila.models.accounts.AccountManager; +import org.ntlab.nemophila.models.accounts.Post; import org.springframework.stereotype.Component; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; @Component @Path("/accounts") public class AccountPostRest { @PUT @Path("/{uid}/posts/{pid}") - @Produces(MediaType.APPLICATION_JSON) - public String getAccountPost(@PathParam("uid") String uid, @PathParam("pid") String pid, @FormParam("token") String token, + public void putAccountPost(@PathParam("uid") String uid, @PathParam("pid") String pid, @FormParam("token") String token, @FormParam("genre") String genre, @FormParam("image1") String image1, @FormParam("image2") String image2, - @FormParam("image3") String image3, @FormParam("rate") int rate, @FormParam("comment") String comment) { + @FormParam("image3") String image3, @FormParam("rate") Integer rate, @FormParam("comment") String comment) { + AccountManager am = AccountManager.getInstance(); + Account account = am.getAccount(uid); - return null; + if(account != null && account.getToken().equals(token)) { + Post post = account.getPost(pid); + if (!genre.equals(null)) post.setGenre(genre); + if (!image1.equals(null)) post.setImage1(image1); + if (!image2.equals(null)) post.setImage2(image2); + if (!image3.equals(null)) post.setImage3(image3); + if (!rate.equals(null)) post.setRate(rate); + if (!comment.equals(null)) post.setComment(comment); + } } @DELETE @Path("/{uid}/posts/{pid}") public void deleteAccountPost(@PathParam("uid") String uid, @PathParam("pid") String pid, @FormParam("token") String token){ - + AccountManager am = AccountManager.getInstance(); + Account account = am.getAccount(uid); + + if(account != null){ + 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()); + } else { + account.deletePost(post); + } + } } }