Newer
Older
CactusServer / src / main / java / cactusServer / resources / AccountsRest.java
y-ota on 31 May 2018 1 KB b
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) {
			return session;
		}
		else {
			int status = 400;
			return null;
		}
		
	}
	


	@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) {
		return Accounts.getInstance().createAcount(userID, userName, userPass);
	}

	@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);
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public ArrayList<Account> getAccounts(){
		return Accounts.getInstance().getAccounts();
	}

}