aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-29 16:25:38 +0300
committerGravatar Vitaly Takmazov2019-04-29 16:25:38 +0300
commitf148f16ac82815f65f0b4ff44e1b2184ec0da0b0 (patch)
tree2c0b90be2036e6513e17a8b8f87c9d89cbeefb66 /src/main/java/com/juick/service
parent465e5571f8af340a3611290eba01c2b1d9fd22cd (diff)
Refactoring
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/UserService.java4
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java12
2 files changed, 8 insertions, 8 deletions
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 3a51dffb..0d4efcfc 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -40,7 +40,7 @@ public interface UserService {
String getSignUpHashByTelegramID(Long telegramId, String username);
- int createUser(String username, String password);
+ Optional<User> createUser(String username, String password);
Optional<User> getUserByUID(int uid);
@@ -66,7 +66,7 @@ public interface UserService {
String getHashByUID(int uid);
- int checkPassword(String username, String password);
+ Optional<User> checkPassword(String username, String password);
boolean updatePassword(User user, String newPassword);
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index bcfb8dac..8d2947f8 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -103,7 +103,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional
@Override
- public int createUser(final String username, final String password) {
+ public Optional<User> createUser(final String username, final String password) {
KeyHolder holder = new GeneratedKeyHolder();
try {
getJdbcTemplate().update(
@@ -117,7 +117,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
},
holder);
} catch (DuplicateKeyException e) {
- return -1;
+ return Optional.empty();
}
int uid = holder.getKeys().size() > 1 ? (int)holder.getKeys().get("id") : holder.getKey().intValue();
@@ -125,7 +125,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
getJdbcTemplate().update("INSERT INTO useroptions(user_id) VALUES (?)", uid);
getJdbcTemplate().update("INSERT INTO subscr_users(user_id, suser_id) VALUES (2, ?)", uid);
- return uid;
+ return getUserByUID(uid);
}
@Transactional(readOnly = true)
@@ -322,7 +322,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional(readOnly = true)
@Override
- public int checkPassword(final String username, final String password) {
+ public Optional<User> checkPassword(final String username, final String password) {
if (StringUtils.isNotBlank(username)) {
List<User> list = getJdbcTemplate().query(
"SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen," +
@@ -337,10 +337,10 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
if (!list.isEmpty()) {
User user = list.get(0);
if (Objects.equals(password, user.getCredentials()))
- return user.getUid();
+ return Optional.of(user);
}
}
- return -1;
+ return Optional.empty();
}
@Transactional