aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/UserServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-09-08 22:38:11 +0300
committerGravatar Vitaly Takmazov2024-09-09 00:33:07 +0300
commitb94d06390216d645c61a27b77324a999ff1c11ef (patch)
treebed05dad9f60567626e4966a04453d8fb5ca92ff /src/main/java/com/juick/service/UserServiceImpl.java
parentfccbba79ff9bb8795b94cae7685807cc3d7fcaf8 (diff)
Clean up social login
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index 0bbeea91..a5ab8432 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -40,6 +40,7 @@ import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
+import java.lang.StackWalker.Option;
import java.net.URI;
import java.sql.*;
import java.time.Instant;
@@ -815,10 +816,15 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional(readOnly = true)
@Override
- public int getUIDbyVKID(long vkID) {
- var users = getJdbcTemplate().queryForList("""
- SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL""", Integer.class, vkID);
- return users.isEmpty() ? 0 : users.get(0);
+ public Optional<User> getUserByVKID(long vkID) {
+ List<User> list = getJdbcTemplate().query(
+ "SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified, premium " +
+ "FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
+ "LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
+ "LEFT JOIN emails e ON e.user_id = u.id WHERE vk.vk_id = ?", new UserMapper(), vkID);
+
+ return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
}
@Transactional