Newer
Older
SproutServerMicro / src / main / java / org / ntlab / SproutServer / accounts / AccountsRest.java
s-bekki on 30 Nov 2017 1 KB initial commit
package org.ntlab.SproutServer.accounts;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;

@Path("accounts")
public class AccountsRest {
    Accounts accounts;

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public Account createAcount(@FormParam("userName") String userName) {
        int userId = accounts.getUserID();
        System.out.println(userName);

        Account newAccount = new Account(accounts.getUserID(),userName);
//		newAccount.setUserName(userName);s
//		accounts.add(new Account(this.userID,userName));
        accounts.getAccounts().add(newAccount);
        userId++;
        accounts.setUserID(userId);

        return newAccount;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public ArrayList<Account> getAccountList() {
        return accounts.getAccounts();
    }

    @Path("/{userID}")
    @PUT
    @Produces(MediaType.APPLICATION_JSON)
    public Account updateAcount(@PathParam("userID") String userID, @FormParam("userName") String userName, @FormParam("mode") String mode) {
        Account editAccount = accounts.getAccounts().get(Integer.valueOf(userID));

        editAccount.setUserName(userName);
        editAccount.setMode(mode);

        accounts.getAccounts().set(Integer.valueOf(userID), editAccount);

        return editAccount;
    }

    @Path("/{userID}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Account getAcount(@PathParam("userID") String userID) {
        Account editAccount = accounts.getAccounts().get(Integer.valueOf(userID));
        return editAccount;
    }

}