From a19d224e5de6a067cc559a23cf6b4afdef060d56 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 1 Dec 2016 15:06:08 +0300 Subject: juick-api: Notifications controller from perl, refactoring --- .../java/com/juick/service/PushQueriesService.java | 18 ++++++++--- .../com/juick/service/PushQueriesServiceImpl.java | 36 +++++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'juick-server/src/main/java/com/juick/service') diff --git a/juick-server/src/main/java/com/juick/service/PushQueriesService.java b/juick-server/src/main/java/com/juick/service/PushQueriesService.java index 2e2ac390..7d4bc295 100644 --- a/juick-server/src/main/java/com/juick/service/PushQueriesService.java +++ b/juick-server/src/main/java/com/juick/service/PushQueriesService.java @@ -7,17 +7,27 @@ import java.util.List; * Created by aalexeev on 11/13/16. */ public interface PushQueriesService { - List getAndroidRegID(int uid); + List getGCMRegID(int uid); - List getAndroidTokens(Collection uids); + List getGCMTokens(Collection uids); - List getWinPhoneURL(int uid); + boolean addGCMToken(Integer uid, String token); - List getWindowsTokens(Collection uids); + boolean deleteGCMToken(String token); + + List getMPNSURL(int uid); + + List getMPNSTokens(Collection uids); + + boolean addMPNSToken(Integer uid, String token); + + boolean deleteMPNSToken(String token); List getAPNSToken(int uid); List getAPNSTokens(Collection uids); + boolean addAPNSToken(Integer uid, String token); + boolean deleteAPNSToken(String token); } diff --git a/juick-server/src/main/java/com/juick/service/PushQueriesServiceImpl.java b/juick-server/src/main/java/com/juick/service/PushQueriesServiceImpl.java index b11f0a79..aca48a19 100644 --- a/juick-server/src/main/java/com/juick/service/PushQueriesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/PushQueriesServiceImpl.java @@ -24,7 +24,7 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri } @Override - public List getAndroidRegID(final int uid) { + public List getGCMRegID(final int uid) { return getJdbcTemplate().queryForList( "SELECT regid FROM android WHERE user_id=?", String.class, @@ -32,7 +32,7 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri } @Override - public List getAndroidTokens(final Collection uids) { + public List getGCMTokens(final Collection uids) { if (CollectionUtils.isEmpty(uids)) return Collections.emptyList(); @@ -43,7 +43,18 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri } @Override - public List getWinPhoneURL(final int uid) { + public boolean addGCMToken(Integer uid, String token) { + return getJdbcTemplate().update("INSERT IGNORE INTO android(user_id,regid) VALUES (?, ?)", + uid, token) > 0; + } + + @Override + public boolean deleteGCMToken(String token) { + return getJdbcTemplate().update("DELETE FROM android WHERE regid=?", token) > 0; + } + + @Override + public List getMPNSURL(final int uid) { return getJdbcTemplate().queryForList( "SELECT url FROM winphone WHERE user_id=?", String.class, @@ -51,7 +62,7 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri } @Override - public List getWindowsTokens(final Collection uids) { + public List getMPNSTokens(final Collection uids) { if (CollectionUtils.isEmpty(uids)) return Collections.emptyList(); @@ -61,6 +72,17 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri String.class); } + @Override + public boolean addMPNSToken(Integer uid, String token) { + return getJdbcTemplate().update("INSERT IGNORE INTO winphone(user_id,url) VALUES (?, ?)", + uid, token) > 0; + } + + @Override + public boolean deleteMPNSToken(String token) { + return getJdbcTemplate().update("DELETE FROM winphone WHERE url=?", token) > 0; + } + @Override public List getAPNSToken(final int uid) { return getJdbcTemplate().queryForList( @@ -84,4 +106,10 @@ public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueri new MapSqlParameterSource("ids", uids), String.class); } + + @Override + public boolean addAPNSToken(Integer uid, String token) { + return getJdbcTemplate().update("INSERT IGNORE INTO ios(user_id,token) VALUES (?, ?)", + uid, token) > 0; + } } -- cgit v1.2.3