diff --git a/src/main/java/com/example/cosmos_serversb/models/Users.java b/src/main/java/com/example/cosmos_serversb/models/Users.java index 8820815..4450341 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Users.java +++ b/src/main/java/com/example/cosmos_serversb/models/Users.java @@ -1,21 +1,32 @@ package com.example.cosmos_serversb.models; + import java.util.UUID; import javax.inject.Singleton; + import com.example.cosmos_serversb.entities.*; @Singleton public class Users { + private static Users theInstance = null; + private Users() { } - + + public static Users getInstance() { + if (theInstance == null) { + theInstance = new Users(); + } + return theInstance; + } + public static User createUser(String name, String pw, String iconImage) { User testUser = new User("test", "123456789", "http://test.com", "testpw", null, "123456789", "http://iconuri/123456789.com"); - testUser.token.add(createToken(testUser.uId)); - testUser.token.add(createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } - public static String createToken(String uId){ + public static String createToken(String uId) { //Tokenを作成しuIdと関連付けしDBに保存し作成したTokenを返す String token = UUID.randomUUID().toString(); return token; @@ -23,22 +34,22 @@ public static User setUser(String uId, String name, String pw, String iconImage) { User testUser = new User("test", "123456789", "http://test.com", "testpw", null, "123456789", "http://iconuri/123456789.com"); - testUser.token.add(createToken(testUser.uId)); - testUser.token.add(createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static User getUserById(String uId) { User testUser = new User("test", "123456789", "http://test.com", "testpw", null, "123456789", "http://iconuri/123456789.com"); - testUser.token.add(createToken(testUser.uId)); - testUser.token.add(createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } public static User getUserByToken(String token) { User testUser = new User("test", "123456789", "http://test.com", "testpw", null, "123456789", "http://iconuri/123456789.com"); - testUser.token.add(createToken(testUser.uId)); - testUser.token.add(createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); + testUser.token.add(getInstance().createToken(testUser.uId)); return testUser; } @@ -47,7 +58,7 @@ } public static String login(String uId) { - return createToken(uId);//testToken + return getInstance().createToken(uId);//testToken } public static DeleteResult logout(String token) {