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 03a07ea..bb92a52 100644 --- a/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java +++ b/src/main/java/org/ntlab/amaryllis/server/resources/VoicememosRest.java @@ -135,100 +135,100 @@ throw new WebApplicationException(400); } -// -// @Path("/{vid}") -// @PUT -// @Produces(MediaType.APPLICATION_JSON) -// public void 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){ -// throw new WebApplicationException(400); -// } -// String server_token = account.getToken(); -// if (client_token.equals(server_token)) { -// Voicememo v = voicememos.getVoicememo(vid); -// v.addFavolist(uid); -// } -// throw new WebApplicationException(400); -// } -// -// @Path("/{vid}") -// @DELETE -// @Produces(MediaType.APPLICATION_JSON) -// public void 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){ -// throw new WebApplicationException(400); -// } -// String server_token = account.getToken(); -// if (client_token.equals(server_token)) { -// Voicememo v = voicememos.getVoicememo(vid); -// v.removeFavolist(uid); -// } -// throw new WebApplicationException(400); -// } -// -// @Path("/{vid}") -// @POST -// @Produces(MediaType.APPLICATION_JSON) -// public void 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){ -// throw new WebApplicationException(400); -// } -// String server_token = account.getToken(); -// if (client_token.equals(server_token)) { -// Voicememo v = voicememos.getVoicememo(vid); -// v.addTimes(); -// } -// throw new WebApplicationException(400); -// } -// -// @Path("/{vid}") -// @POST -// @Produces(MediaType.APPLICATION_JSON) -// public void addComment(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("comment") String comment){ -// if (vid == null || client_token == null || uid == null) { -// throw new WebApplicationException(400); -// } -// Account account = accounts.getAccount(uid); -// if(account == null){ -// throw new WebApplicationException(400); -// } -// String server_token = account.getToken(); -// if (client_token.equals(server_token)) { -// Voicememo v = voicememos.getVoicememo(vid); -// v.createComment(uid, comment); -// } -// throw new WebApplicationException(400); -// } -// -// @Path("/{vid}") -// @DELETE -// @Produces(MediaType.APPLICATION_JSON) -// public void deleteComment(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("comment") String commentId){ -// if (vid == null || client_token == null || uid == null || commentId == null) { -// throw new WebApplicationException(400); -// } -// Account account = accounts.getAccount(uid); -// if(account == null){ -// throw new WebApplicationException(400); -// } -// String server_token = account.getToken(); -// if (client_token.equals(server_token)) { -// Voicememo v = voicememos.getVoicememo(vid); -// v.removeComment(commentId); -// } -// throw new WebApplicationException(400); -// } + + @Path("/{vid}/myfavo") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void 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){ + throw new WebApplicationException(400); + } + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.addFavolist(uid); + } + throw new WebApplicationException(400); + } + + @Path("/{vid}/myfavo") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void 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){ + throw new WebApplicationException(400); + } + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.removeFavolist(uid); + } + throw new WebApplicationException(400); + } + + @Path("/{vid}/times") + @POST + @Produces(MediaType.APPLICATION_JSON) + public void 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){ + throw new WebApplicationException(400); + } + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.addTimes(); + } + throw new WebApplicationException(400); + } + + @Path("/{vid}/comments") + @POST + @Produces(MediaType.APPLICATION_JSON) + public void addComment(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid, @FormParam("comment") String comment){ + if (vid == null || client_token == null || uid == null) { + throw new WebApplicationException(400); + } + Account account = accounts.getAccount(uid); + if(account == null){ + throw new WebApplicationException(400); + } + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.createComment(uid, comment); + } + throw new WebApplicationException(400); + } + + @Path("/{vid}/comments/{commentNo}") + @DELETE + @Produces(MediaType.APPLICATION_JSON) + public void deleteComment(@PathParam("vid") String vid, @FormParam("token") String client_token, @FormParam("uid") String uid, @PathParam("commentNo") String commentNo){ + if (vid == null || client_token == null || uid == null || commentNo == null) { + throw new WebApplicationException(400); + } + Account account = accounts.getAccount(uid); + if(account == null){ + throw new WebApplicationException(400); + } + String server_token = account.getToken(); + if (client_token.equals(server_token)) { + Voicememo v = voicememos.getVoicememo(vid); + v.removeComment(commentNo); + } + throw new WebApplicationException(400); + } }