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 a775751..e118f65 100644 --- a/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java +++ b/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java @@ -7,9 +7,12 @@ 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.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; @Component @@ -20,50 +23,73 @@ @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 = ""; + public Map getVoicememos(@QueryParam("latmax") Double latmax, @QueryParam("latmin") Double latmin, @QueryParam("longmax") Double longmax, @QueryParam("longmin") Double longmin) { + if (latmax == null || latmin == null || longmax == null || longmin == null) { + throw new WebApplicationException(400); + } + Map gettingVid = new HashMap(); + ArrayList vidlist = new ArrayList<>(); 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; + if (latmax > latitude && latitude > latmin && longmax > longitude && longitude > longmin ) { + vidlist.add(vid); } } - return vidlist; + gettingVid.put("voicememos",vidlist); + return gettingVid; } @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) { + public String addVoicememos(@FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("time") Integer time, @FormParam("data") String data, @FormParam("latitude") Double latitude, @FormParam("longitude") Double longitude, @FormParam("title") String title, @FormParam("summary") String summary) { + if (client_token == null || uid == null || time == null || data == null || latitude == null || longitude == null || title == null) { + throw new WebApplicationException(400); + } Account account = accounts.getAccount(uid); String server_token = account.getToken(); - if (client_token.equals(server_token)) { + if (client_token.equals(server_token)) { Voicememo v = voicememos.createVoicememo(uid, time, data, latitude, longitude, title, summary); + if (v == null) { + throw new WebApplicationException(400); + } String vid = v.getVid(); return vid; } - return null; + Voicememo v = voicememos.createVoicememo(uid, time, data, latitude, longitude, title, summary); + if (v == null) { + throw new WebApplicationException(400); + } + + throw new WebApplicationException(400); } @Path("/{vid}") @GET @Produces(MediaType.APPLICATION_JSON) - public Voicememo getVoicememo(@PathParam("vid") String vid, @QueryParam("token") String client_token, @QueryParam("uid") String uid, @QueryParam("time") int time) { + public Voicememo getVoicememo(@PathParam("vid") String vid, @QueryParam("token") String client_token, @QueryParam("uid") String uid, @QueryParam("time") Integer time) { + if (vid == null || client_token == null || uid == null) { + throw new WebApplicationException(400); + } 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; + + throw new WebApplicationException(400); } @Path("/{vid}") @PUT @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) { + if (vid == null || client_token == null || uid == null || title == null) { + throw new WebApplicationException(400); + } Account account = accounts.getAccount(uid); String server_token = account.getToken(); if (client_token.equals(server_token)) { @@ -72,20 +98,23 @@ v.setTitle(title); return; } - + throw new WebApplicationException(400); } @Path("/{vid}") @DELETE @Produces(MediaType.APPLICATION_JSON) - public void deleteVoicememo(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid){ + public void deleteVoicememo(@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); String server_token = account.getToken(); if (client_token.equals(server_token)) { voicememos.removeVoicememo(vid); return; } - + throw new WebApplicationException(400); } }