From b2f3afebc7de684d1d49042f5f79a9cbf9c1f2f2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 14 Mar 2018 10:04:40 +0300 Subject: refactor email settings --- .../src/main/java/com/juick/service/EmailServiceImpl.java | 8 ++++++++ .../src/main/java/com/juick/service/UserServiceImpl.java | 12 ------------ 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'juick-server-jdbc/src/main') diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java index 1921354a..0cccc915 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java @@ -68,6 +68,14 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService { .addValue("email", account)) > 0; } + @Transactional(readOnly = true) + @Override + public String getNotificationsEmail(Integer userId) { + List list = getJdbcTemplate().queryForList( + "SELECT email FROM emails WHERE user_id=? AND subscr_hour IS NOT NULL", String.class, userId); + return list.isEmpty() ? StringUtils.EMPTY : list.get(0); + } + @Override public boolean setNotificationsEmail(Integer userId, String account) { getJdbcTemplate().update("UPDATE emails SET subscr_hour=NULL WHERE user_id=?", userId); diff --git a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java index 770819ec..3f7cebf6 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java @@ -20,13 +20,11 @@ package com.juick.service; import com.juick.User; import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.Auth; -import com.juick.server.helpers.EmailOpts; import com.juick.server.helpers.UserInfo; import com.juick.server.util.HashUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.dao.DuplicateKeyException; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; @@ -34,7 +32,6 @@ import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import javax.inject.Inject; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -627,15 +624,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return getJdbcTemplate().queryForList("SELECT email FROM emails WHERE user_id=?", String.class, user.getUid()); } - @Transactional(readOnly = true) - @Override - public EmailOpts getEmailOpts(final User user) { - List list = getJdbcTemplate().query( - "SELECT email,subscr_hour FROM emails WHERE user_id=? AND subscr_hour IS NOT NULL", - (rs, num) -> new EmailOpts(rs.getString(1), rs.getInt(2)), user.getUid()); - return list.isEmpty() ? new EmailOpts("", 0) : list.get(0); - } - @Transactional(readOnly = true) @Override public String getEmailHash(final User user) { -- cgit v1.2.3