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 1d03b33..333391d 100644 --- a/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java +++ b/src/main/java/org/ntlab/nemophila/resources/accounts/AccountPostRest.java @@ -4,15 +4,24 @@ import org.ntlab.nemophila.models.accounts.AccountManager; import org.ntlab.nemophila.models.accounts.Post; import org.ntlab.nemophila.models.shops.Shop; +import org.ntlab.nemophila.utils.Base64Decode; +import org.springframework.beans.BeansException; import org.springframework.stereotype.Component; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.IOException; @Component @Path("/accounts") public class AccountPostRest { + private org.springframework.context.ApplicationContext applicationContext; + + public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + @PUT @Path("/{uid}/posts/{pid}") public void putAccountPost(@PathParam("uid") String uid, @PathParam("pid") String pid, @FormParam("token") String token, @@ -21,14 +30,27 @@ AccountManager am = AccountManager.getInstance(); Account account = am.getAccount(uid); + String pathDirectory = ""; + if(account != null && account.getToken().equals(token)) { Post post = account.getPost(pid); + String[] images = {image1, image2, image3}; + if (genre != null) post.setGenre(genre); if (image1 != null) post.setImage1(image1); if (image2 != null) post.setImage2(image2); if (image3 != null) post.setImage3(image3); if (rate != null) post.setRate(rate); if (comment != null) post.setComment(comment); + + try { + pathDirectory = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/nemophila-data"; + Base64Decode.savePostImage(uid, post.getId(), pathDirectory, images); + } catch (IOException e){ + e.printStackTrace(); + throw new WebApplicationException(500); + } + } else { var response = Response.status(Response.Status.NO_CONTENT); response.status(401).entity("tokenの認証に失敗");