diff --git a/src/main/java/cactusServer/entities/Account.java b/src/main/java/cactusServer/entities/Account.java index e0dfb91..431ced0 100644 --- a/src/main/java/cactusServer/entities/Account.java +++ b/src/main/java/cactusServer/entities/Account.java @@ -1,10 +1,9 @@ package cactusServer.entities; public class Account { - private int id; - private String name; + private String id,name,pass; - public Account(int userId, String userName) { + public Account(String userId, String userName) { setId(userId); setName(userName); } @@ -13,11 +12,11 @@ } - public int getId() { + public String getId() { return id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } @@ -28,4 +27,12 @@ public void setName(String name) { this.name = name; } + + public String getPass() { + return pass; + } + + public void setPass(String pass) { + this.pass = pass; + } } diff --git a/src/main/java/cactusServer/models/Accounts.java b/src/main/java/cactusServer/models/Accounts.java index 8c86756..1e7c3b0 100644 --- a/src/main/java/cactusServer/models/Accounts.java +++ b/src/main/java/cactusServer/models/Accounts.java @@ -1,20 +1,15 @@ package cactusServer.models; -import javax.ws.*; import javax.inject.Singleton; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import cactusServer.entities.Account; import java.util.ArrayList; @Singleton -@Path("/accounts") public class Accounts { private static Accounts theInstance = null; private ArrayList accounts = new ArrayList(); - private int userID = 0; public Accounts() { if (theInstance == null) { @@ -29,67 +24,40 @@ return theInstance; } - @POST - @Produces(MediaType.APPLICATION_JSON) - public Account createAcount(@FormParam("userName") String userName) { + public Account createAcount(String userID,String userName) { System.out.println(userName); - Account newAccount = new Account(this.userID, userName); - // newAccount.setUserName(userName); - // accounts.add(new Account(this.userID,userName)); + Account newAccount = new Account(userID, userName); accounts.add(newAccount); - this.userID++; System.out.println(userID); return newAccount; } - public void createAccount(int userId) { + public void createAccount(String userId) { Account newAccount = new Account(userId, "user" + userId); accounts.add(newAccount); System.out.println(accounts.size()); } - @GET - @Produces(MediaType.APPLICATION_JSON) public ArrayList getAccountList() { return this.accounts; } - @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.get(Integer.valueOf(userID)); - - accounts.set(Integer.valueOf(userID), editAccount); - - return editAccount; - } - - @Path("/{userID}") - @GET - @Produces(MediaType.APPLICATION_JSON) - public Account getAcount(@PathParam("userID") String userID) { + public Account getAcount(String userID) { Account editAccount = accounts.get(Integer.valueOf(userID)); return editAccount; } public Accounts getAccount() { Account ac = new Account(); - this.userID = ac.getId(); return new Accounts(); } - - public boolean checkCreatedUser(int userId) { - for (Account account : accounts) { - if (account.getId() == userId) { - return true; - } - } - return false; + + public String deleteAccount(int userID) { + accounts.remove(userID); + return "complated remove account"; } public ArrayList getAccounts() { @@ -100,11 +68,4 @@ this.accounts = accounts; } - public String getUserNameById(int userId) { - for (Account account : accounts) { - if (account.getId() == userId) - return account.getName(); - } - return "nameNone"; - } } diff --git a/src/main/java/cactusServer/resources/AccountsRest.java b/src/main/java/cactusServer/resources/AccountsRest.java index b1975ae..eb88533 100644 --- a/src/main/java/cactusServer/resources/AccountsRest.java +++ b/src/main/java/cactusServer/resources/AccountsRest.java @@ -1,14 +1,21 @@ package cactusServer.resources; -import javax.ws.*; -import javax.inject.Singleton; -import javax.ws.rs.Path; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; -import java.util.ArrayList; +import cactusServer.models.Accounts; - -@Singleton -@Path("AccontsRest") +@Path("AccountsRest") public class AccountsRest { - + @POST + @Path("/login") + @Produces(MediaType.APPLICATION_JSON) + public String loginAccount(String userID,String userPass) { + return ""; + } + @POST + @Path("/logout") + @Produces(MediaType.APPLICATION_JSON) + public String logoutAccount(String userID,String userPass) { + return ""; + } } diff --git a/src/main/java/test/app/App.java b/src/main/java/test/app/App.java new file mode 100644 index 0000000..0bd8958 --- /dev/null +++ b/src/main/java/test/app/App.java @@ -0,0 +1,12 @@ +package test.app; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +import org.glassfish.jersey.server.ResourceConfig; + +@SuppressWarnings("unused") +@ApplicationPath("/rest") +public class App extends ResourceConfig { + +} \ No newline at end of file diff --git a/src/test/java/test/app/App.java b/src/test/java/test/app/App.java deleted file mode 100644 index 0bd8958..0000000 --- a/src/test/java/test/app/App.java +++ /dev/null @@ -1,12 +0,0 @@ -package test.app; - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -import org.glassfish.jersey.server.ResourceConfig; - -@SuppressWarnings("unused") -@ApplicationPath("/rest") -public class App extends ResourceConfig { - -} \ No newline at end of file