| | package cactusServer.resources; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | |
---|
| | import javax.servlet.http.HttpServletResponse; |
---|
| | import javax.ws.rs.*; |
---|
| | import javax.ws.rs.core.MediaType; |
---|
| | |
---|
| | import cactusServer.entities.*; |
---|
| | import cactusServer.models.Accounts; |
---|
| | |
---|
| | @Path("/accounts") |
---|
| | public class AccountsRest { |
---|
| | private HttpServletResponse response; |
---|
| | |
---|
| | @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) { |
---|
| | if (session != null) { |
---|
| | return session; |
---|
| | } else { |
---|
| | throw new WebApplicationException(400); |
---|
| | } |
---|
| | else { |
---|
| | int status = 400; |
---|
| | return null; |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | @POST |
---|
| | @Path("/logout") |
---|
| | @Produces(MediaType.APPLICATION_JSON) |
---|
| |
---|
| | @POST |
---|
| | @Produces(MediaType.APPLICATION_JSON) |
---|
| | public URIAddressedEntity createAccount(@FormParam("userID") String userID, @FormParam("userName") String userName, |
---|
| | @FormParam("userPass") String userPass) { |
---|
| | return Accounts.getInstance().createAcount(userID, userName, 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(@FormParam("uniqueID") String uniqueID) { |
---|
| | return Accounts.getInstance().deleteAccount(uniqueID); |
---|
| | 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(){ |
---|
| | public ArrayList<Account> getAccounts() { |
---|
| | return Accounts.getInstance().getAccounts(); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
k(ry
確認.
1c4bd98
intomaster
fromAccounts
on 7 Jun 2018