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 da8eede..a775751 100644 --- a/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java +++ b/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java @@ -19,29 +19,29 @@ Accounts accounts = Accounts.getInstance(); @GET + @Produces(MediaType.APPLICATION_JSON) public String getVoicememos(@QueryParam("latmax") double latmax, @QueryParam("latmin") double latmin, @QueryParam("longmax") double longmax, @QueryParam("longmin") double longmin) { String vidlist = ""; -// for (Voicememo v : -// voicememos) { -// String vid = v.getVid(); -// double latitude = v.getLatitude(); -// double longitude = v.getLongitude(); -// if (latmax > latitude && latitude > latmin && longmax > longitude && longmin > longitude) { -// vidlist = vidlist + vid; -// } -// } + for (Voicememo v : + voicememos.getVoicememos()) { + String vid = v.getVid(); + double latitude = v.getLatitude(); + double longitude = v.getLongitude(); + if (latmax > latitude && latitude > latmin && longmax > longitude && longmin > longitude) { + vidlist = vidlist + vid; + } + } return vidlist; } @POST + @Produces(MediaType.APPLICATION_JSON) public String addVoicememos(@FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("time") int time, @FormParam("data") String data, @FormParam("latitude") double latitude, @FormParam("longitude") double longitude, @FormParam("title") String title, @FormParam("summary") String summary) { - String vid = ""; Account account = accounts.getAccount(uid); String server_token = account.getToken(); - if (client_token == server_token) { - UUID uuid = UUID.randomUUID(); - vid = uuid.toString(); - voicememos.createVoicememo(uid, time, data, latitude, longitude, title, summary); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.createVoicememo(uid, time, data, latitude, longitude, title, summary); + String vid = v.getVid(); return vid; } return null; @@ -49,13 +49,42 @@ @Path("/{vid}") @GET - public String getVoicememo() { - String voicememo = ""; - return voicememo; + @Produces(MediaType.APPLICATION_JSON) + public Voicememo getVoicememo(@PathParam("vid") String vid, @QueryParam("token") String client_token, @QueryParam("uid") String uid, @QueryParam("time") int time) { + Account account = accounts.getAccount(uid); + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo voicememo = voicememos.getVoicememo(vid); + return voicememo; + } + return null; } + @Path("/{vid}") @PUT - public void correctVicememo() { + @Produces(MediaType.APPLICATION_JSON) + public void correctVoicememo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("title") String title, @FormParam("summary") String summary) { + Account account = accounts.getAccount(uid); + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.setSummary(summary); + v.setTitle(title); + return; + } + + } + + @Path("/{vid}") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void deleteVoicememo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid){ + Account account = accounts.getAccount(uid); + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + voicememos.removeVoicememo(vid); + return; + } }