Accounts #45

Merged r-isitani merged 3 commits into nitta-lab-2018:master from nitta-lab-2018:Accounts on 7 Jun 2018
Showing 2 changed files
View
4
src/main/java/cactusServer/models/Accounts.java
return null;
}
 
public URIAddressedEntity loginAccount(String userID, String userPass) {
if (getAccountByID(userID).getPass().equals(userPass)) {
if (getAccountByID(userID) != null && getAccountByID(userID).getPass().equals(userPass)) {
Accounts.getInstance().getAccountByID(userID).setLogin(true);
Accounts.getInstance().getAccountByID(userID).formToken();
session = new URIAddressedEntity(
"/CactusServer/rest/accounts/" + Accounts.getInstance().getAccountByID(userID).getUniqueID(),
}
 
public Account deleteAccount(String uniqueID) {
Account edit = Accounts.getInstance().getAccountByuniqueID(uniqueID);
if(edit == null) {
if (edit == null) {
return edit;
}
userIDSet.remove(edit.getId());
uniqueIDSet.remove(edit.getUniqueID());
View
44
src/main/java/cactusServer/resources/AccountsRest.java
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();
}
 
}