aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-05-21 12:10:32 +0300
committerGravatar Vitaly Takmazov2020-05-21 12:12:08 +0300
commitb550d376b0f62bbe914da26500524acf5be22494 (patch)
tree048ac409c6a17f5998433d627668a16c5fd0f9bc /src/main/java/com/juick/service
parentdeef9ad990c3f5902b1556edbf93dabf223ac175 (diff)
Show correct signup errors
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/UserService.java3
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java5
2 files changed, 5 insertions, 3 deletions
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index fbbab0ad..16d76659 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -20,6 +20,7 @@ package com.juick.service;
import com.juick.model.Message;
import com.juick.model.User;
import com.juick.model.AuthResponse;
+import com.juick.util.UsernameTakenException;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -39,7 +40,7 @@ public interface UserService {
String getSignUpHashByTelegramID(Long telegramId, String username);
- Optional<User> createUser(String username, String password);
+ Optional<User> createUser(String username, String password) throws UsernameTakenException;
Optional<User> getUserByUID(int uid);
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index 84ff1ff5..cf1c838d 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -21,6 +21,7 @@ import com.juick.model.Message;
import com.juick.model.User;
import com.juick.model.AnonymousUser;
import com.juick.model.AuthResponse;
+import com.juick.util.UsernameTakenException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -108,7 +109,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional
@Override
- public Optional<User> createUser(final String username, final String password) {
+ public Optional<User> createUser(final String username, final String password) throws UsernameTakenException {
KeyHolder holder = new GeneratedKeyHolder();
try {
getJdbcTemplate().update(
@@ -122,7 +123,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
},
holder);
} catch (DuplicateKeyException e) {
- return Optional.empty();
+ throw new UsernameTakenException();
}
int uid = holder.getKeys().size() > 1 ? (int)holder.getKeys().get("id") : holder.getKey().intValue();