aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-08 21:38:27 +0300
committerGravatar Vitaly Takmazov2018-11-08 21:38:27 +0300
commit7aaa3f9a29c280f01c677c918932620be45cdbd7 (patch)
tree39947b2c889afd08f9c73ba54fab91159d2af258 /juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java
parent3ea9770d0d43fbe45449ac4531ec4b0a374d98ea (diff)
Merge everything into single Spring Boot application
Diffstat (limited to 'juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java')
-rw-r--r--juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java71
1 files changed, 0 insertions, 71 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java
deleted file mode 100644
index 57101ffe..00000000
--- a/juick-server/src/main/java/com/juick/service/MessengerServiceImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.juick.service;
-
-import com.juick.User;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
-
-@Repository
-public class MessengerServiceImpl extends BaseJdbcService implements MessengerService {
-
- @Transactional(readOnly = true)
- @Override
- public Integer getUserId(String senderId) {
- List<Integer> list = getJdbcTemplate().queryForList(
- "SELECT id FROM users INNER JOIN messenger " +
- "ON messenger.user_id = users.id WHERE messenger.sender_id=?", Integer.class, senderId);
-
- return list.isEmpty() ? 0 : list.get(0);
- }
- @Transactional(readOnly = true)
- @Override
- public Optional<String> getSenderId(User user) {
- List<String> list = getJdbcTemplate().queryForList(
- "SELECT sender_id FROM messenger " +
- "WHERE user_id=?", String.class, user.getUid());
-
- return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
- }
-
- @Transactional
- @Override
- public boolean createMessengerUser(String senderId, String displayName) {
- return getJdbcTemplate().update(
- "INSERT INTO messenger(sender_id, display_name, loginhash) VALUES(?,?,?)",
- senderId, displayName, UUID.randomUUID().toString()) > 0;
- }
- @Transactional(readOnly = true)
- @Override
- public String getDisplayName(String hash) {
- try {
- return getJdbcTemplate().queryForObject("SELECT display_name FROM messenger WHERE loginhash=?", String.class, hash);
- } catch (EmptyResultDataAccessException e) {
- return null;
- }
- }
- @Transactional
- @Override
- public String getSignUpHash(final String senderId, final String username) {
- List<String> list = getJdbcTemplate().queryForList(
- "SELECT loginhash FROM messenger WHERE sender_id = ? AND user_id IS NULL",
- String.class,
- senderId);
-
- if (list.isEmpty()) {
- String hash = UUID.randomUUID().toString();
- getJdbcTemplate().update(
- "INSERT INTO messenger(sender_id, loginhash, display_name) VALUES (?, ?, ?)", senderId, hash, username);
- return hash;
- }
- return list.get(0);
- }
- @Transactional
- @Override
- public boolean linkMessengerUser(String hash, int uid) {
- return getJdbcTemplate().update("UPDATE messenger SET user_id=?, loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
- }
-}