diff --git a/src/main/java/cactusServer/resources/AccountsRest.java b/src/main/java/cactusServer/resources/AccountsRest.java index dd5af7e..8837022 100644 --- a/src/main/java/cactusServer/resources/AccountsRest.java +++ b/src/main/java/cactusServer/resources/AccountsRest.java @@ -7,16 +7,17 @@ import cactusServer.entities.*; import cactusServer.models.Accounts; +import net.arnx.jsonic.JSON; @Path("/accounts") public class AccountsRest { @PUT //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public URIAddressedAccount loginAccount(@FormParam("userID") String userID, @FormParam("userPass") String userPass) { + public String loginAccount(@FormParam("userID") String userID, @FormParam("userPass") String userPass) { URIAddressedAccount session = Accounts.getInstance().loginAccount(userID, userPass); if (session != null) { - return session; + return JSON.encode(session); } else { throw new WebApplicationException(400); } @@ -26,18 +27,18 @@ @Path("/logout") //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Account logoutAccount(@FormParam("token") String token) { - return Accounts.getInstance().logoutAccount(token); + public String logoutAccount(@FormParam("token") String token) { + return JSON.encode(Accounts.getInstance().logoutAccount(token)); } @POST //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public URIAddressedAccount createAccount(@FormParam("userID") String userID, @FormParam("userName") String userName, + public String createAccount(@FormParam("userID") String userID, @FormParam("userName") String userName, @FormParam("userPass") String userPass) { URIAddressedAccount editAccount = Accounts.getInstance().createAcount(userID, userName, userPass); if (editAccount != null) { - return editAccount; + return JSON.encode(editAccount); } else { throw new WebApplicationException(409); } @@ -47,17 +48,17 @@ @Path("/{uniqueID}") //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Account getAccount(@PathParam("uniqueID") String uniqueID) { - return Accounts.getInstance().getAccountByuniqueID(uniqueID); + public String getAccount(@PathParam("uniqueID") String uniqueID) { + return JSON.encode(Accounts.getInstance().getAccountByuniqueID(uniqueID)); } @DELETE @Path("/{uniqueID}") //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Account deleteAccount(@PathParam("uniqueID") String uniqueID) { + public String deleteAccount(@PathParam("uniqueID") String uniqueID) { if (Accounts.getInstance().getAccountByuniqueID(uniqueID) != null) { - return Accounts.getInstance().deleteAccount(uniqueID); + return JSON.encode(Accounts.getInstance().deleteAccount(uniqueID)); } else { throw new WebApplicationException(400); } @@ -66,8 +67,8 @@ @GET //@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public ArrayList getAccounts() { - return Accounts.getInstance().getAccounts(); + public String getAccounts() { + return JSON.encode(Accounts.getInstance().getAccounts()); } }