package cactusServer.resources; import java.util.ArrayList; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import cactusServer.entities.*; import cactusServer.models.Accounts; @Path("/accounts") public class AccountsRest { @PUT @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity loginAccount(@FormParam("userID") String userID, @FormParam("userPass") String userPass) { URIAddressedEntity session = Accounts.getInstance().loginAccount(userID, userPass); if (session != null) { return session; } else { throw new WebApplicationException(400); } } @POST @Path("/logout") @Produces(MediaType.APPLICATION_JSON) public Account logoutAccount(@FormParam("token") String token) { return Accounts.getInstance().logoutAccount(token); } @POST @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity createAccount(@FormParam("userID") String userID, @FormParam("userName") String userName, @FormParam("userPass") String userPass) { URIAddressedEntity editAccount = Accounts.getInstance().createAcount(userID, userName, userPass); if (editAccount != null) { return editAccount; } else { throw new WebApplicationException(409); } } @GET @Path("/{uniqueID}") @Produces(MediaType.APPLICATION_JSON) public Account getAccount(@PathParam("uniqueID") String uniqueID) { return Accounts.getInstance().getAccountByuniqueID(uniqueID); } @DELETE @Path("/{uniqueID}") @Produces(MediaType.APPLICATION_JSON) public Account deleteAccount(@PathParam("uniqueID") String uniqueID) { if (Accounts.getInstance().getAccountByuniqueID(uniqueID) != null) { return Accounts.getInstance().deleteAccount(uniqueID); } else { throw new WebApplicationException(400); } } @GET @Produces(MediaType.APPLICATION_JSON) public ArrayList<Account> getAccounts() { return Accounts.getInstance().getAccounts(); } }