diff --git a/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java b/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java index 801912a..6fd3011 100644 --- a/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java +++ b/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java @@ -5,26 +5,30 @@ import org.ntlab.amaryllis.server.models.Accounts; import org.ntlab.amaryllis.server.models.Voicememos; import org.ntlab.amaryllis.server.utils.Base64Decode; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; + import javax.ws.rs.*; -import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; -import java.awt.*; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import static org.ntlab.amaryllis.server.models.Voicememos.createVid; -import static org.ntlab.amaryllis.server.utils.Base64Decode.saveAsFile; @Component @Path("/voicememos") -public class VoicememosRest { +public class VoicememosRest implements ApplicationContextAware { Voicememos voicememos = Voicememos.getInstance(); Accounts accounts = Accounts.getInstance(); + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } //ใƒ†ใ‚นใƒˆ็”จ { @@ -34,8 +38,9 @@ Account b = accounts.getAccount("hogehoge"); b.setToken("hoge_token"); } + { - voicememos.createVoicememo("vid","test",1,"url",3,3,"a","a"); + voicememos.createVoicememo("vid", "test", 1, "url", 3, 3, "a", "a"); } @GET @@ -49,7 +54,7 @@ voicememos.getVoicememos()) { double latitude = v.getLatitude(); double longitude = v.getLongitude(); - if (latmax > latitude && latitude > latmin && longmax > longitude && longitude > longmin ) { + if (latmax > latitude && latitude > latmin && longmax > longitude && longitude > longmin) { vidlist.add(v); } } @@ -63,7 +68,7 @@ throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); @@ -71,7 +76,8 @@ String vid = createVid(); String path = ""; try { - path = Base64Decode.saveAsFile(vid, data); + path = applicationContext.getResource("file:").getFile().getAbsolutePath(); + path = Base64Decode.saveAsFile(vid, path, data); } catch (IOException e) { e.printStackTrace(); throw new WebApplicationException(500); @@ -95,7 +101,7 @@ throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); @@ -115,7 +121,7 @@ throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); @@ -137,7 +143,7 @@ throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); @@ -153,18 +159,18 @@ @Path("/{vid}/myfavo") @PUT @Produces(MediaType.APPLICATION_JSON) - public String addMyfavo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid){ + public String addMyfavo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid) { if (vid == null || client_token == null || uid == null) { throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); if (client_token.equals(server_token)) { Voicememo v = voicememos.getVoicememo(vid); - if(v == null){ + if (v == null) { throw new WebApplicationException(400); } v.addFavolist(uid); @@ -177,18 +183,18 @@ @Path("/{vid}/myfavo") @DELETE @Produces(MediaType.APPLICATION_JSON) - public String deleteMyfavo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid){ + public String deleteMyfavo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid) { if (vid == null || client_token == null || uid == null) { throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); if (client_token.equals(server_token)) { Voicememo v = voicememos.getVoicememo(vid); - if(v == null){ + if (v == null) { throw new WebApplicationException(400); } v.removeFavolist(uid); @@ -201,18 +207,18 @@ @Path("/{vid}/times") @POST @Produces(MediaType.APPLICATION_JSON) - public String countTimes(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid){ + public String countTimes(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid) { if (vid == null || client_token == null || uid == null) { throw new WebApplicationException(400); } Account account = accounts.getAccount(uid); - if(account == null){ + if (account == null) { throw new WebApplicationException(400); } String server_token = account.getToken(); if (client_token.equals(server_token)) { Voicememo v = voicememos.getVoicememo(vid); - if(v == null){ + if (v == null) { throw new WebApplicationException(400); } v.addTimes(); @@ -223,5 +229,4 @@ } - }