aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r--src/main/java/com/juick/service/TelegramService.java2
-rw-r--r--src/main/java/com/juick/service/TelegramServiceImpl.java10
-rw-r--r--src/main/java/com/juick/service/UserService.java2
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java16
4 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/com/juick/service/TelegramService.java b/src/main/java/com/juick/service/TelegramService.java
index 4acf4cbe..16ba531d 100644
--- a/src/main/java/com/juick/service/TelegramService.java
+++ b/src/main/java/com/juick/service/TelegramService.java
@@ -30,8 +30,6 @@ public interface TelegramService {
List<Long> getAnonymous();
- int getUser(long tgId);
-
boolean createTelegramUser(long tgID, String tgName);
boolean deleteTelegramUser(Integer uid);
diff --git a/src/main/java/com/juick/service/TelegramServiceImpl.java b/src/main/java/com/juick/service/TelegramServiceImpl.java
index 12142e7a..7b893b6b 100644
--- a/src/main/java/com/juick/service/TelegramServiceImpl.java
+++ b/src/main/java/com/juick/service/TelegramServiceImpl.java
@@ -45,16 +45,6 @@ public class TelegramServiceImpl extends BaseJdbcService implements TelegramServ
return getJdbcTemplate().queryForList("SELECT tg_id FROM telegram WHERE user_id IS NULL", Long.class);
}
- @Transactional(readOnly = true)
- @Override
- public int getUser(final long tgId) {
- List<Integer> list = getJdbcTemplate().queryForList(
- "SELECT id FROM users INNER JOIN telegram " +
- "ON telegram.user_id = users.id WHERE telegram.tg_id=?", Integer.class, tgId);
-
- return list.isEmpty() ? 0 : list.get(0);
- }
-
@Transactional
@Override
public boolean createTelegramUser(final long tgID, final String tgName) {
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 8fe8bc1f..8d7f7e02 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -180,6 +180,8 @@ public interface UserService {
String getTelegramNameByHash(String hash);
+ Optional<User> getUserByTelegramId(final Long id);
+
@CacheEvict(value = "users_by_name", allEntries = true)
boolean setFacebookUser(String hash, int uid);
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index ab947bac..69ca7569 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -783,6 +783,22 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return list.isEmpty() ?
StringUtils.EMPTY : list.get(0);
}
+ @Override
+ @Transactional(readOnly = true)
+ public Optional<User> getUserByTelegramId(Long id) {
+ 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
+ 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 t.tg_id = ?""",
+ new UserMapper(), id
+ );
+
+ return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
+ }
@Transactional(readOnly = true)
@Override