aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-16 14:30:50 +0300
committerGravatar Vitaly Takmazov2016-11-16 16:21:53 +0300
commitffb24e0d469aaafa35ad5f460a7bdf771382f0ff (patch)
tree0d8fc9114b916f9058cccb01fcf8281a0a209284 /juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
parente8faf851327a12f28ae664a6f7db6c844d0ba9bf (diff)
server-core -> juick-server
Diffstat (limited to 'juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java')
-rw-r--r--juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
new file mode 100644
index 00000000..ed1cd676
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/service/CrosspostServiceImpl.java
@@ -0,0 +1,96 @@
+package com.juick.service;
+
+import com.juick.server.helpers.ApplicationStatus;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.inject.Inject;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Created by aalexeev on 11/13/16.
+ */
+@Repository
+@Transactional(readOnly = true)
+public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostService {
+
+ @Inject
+ public CrosspostServiceImpl(JdbcTemplate jdbcTemplate) {
+ super(jdbcTemplate, null);
+ }
+
+ @Override
+ public Optional<Pair<String, String>> getTwitterTokens(final int uid) {
+ List<Optional<Pair<String, String>>> list = getJdbcTemplate().query(
+ "SELECT access_token,access_token_secret FROM twitter WHERE user_id = ? AND crosspost = 1",
+ (rs, num) -> Optional.of(Pair.of(rs.getString(1), rs.getString(2))),
+ uid);
+
+ return list.isEmpty() ?
+ Optional.empty() : list.get(0);
+ }
+
+ @Override
+ public Optional<String> getFacebookToken(final int uid) {
+ List<String> list = getJdbcTemplate().queryForList(
+ "SELECT access_token FROM facebook WHERE user_id = ? AND access_token IS NOT NULL AND crosspost = 1",
+ String.class,
+ uid);
+ return list.isEmpty() ?
+ Optional.empty() : Optional.of(list.get(0));
+ }
+
+ @Override
+ public ApplicationStatus getFbCrossPostStatus(final int uid) {
+ List<ApplicationStatus> list = getJdbcTemplate().query(
+ "SELECT 1, crosspost FROM facebook WHERE user_id = ? LIMIT 1",
+ (rs, num) -> {
+ ApplicationStatus status = new ApplicationStatus();
+
+ status.setConnected(rs.getInt(1) > 0);
+ status.setCrosspostEnabled(rs.getBoolean(2));
+
+ return status;
+ },
+ uid);
+
+ return list.isEmpty() ?
+ new ApplicationStatus() : list.get(0);
+ }
+
+ @Override
+ public String getTwitterName(final int uid) {
+ List<String> list = getJdbcTemplate().queryForList(
+ "SELECT uname FROM twitter WHERE user_id = ?",
+ String.class,
+ uid);
+
+ return list.isEmpty() ?
+ "" : list.get(0);
+ }
+
+ @Override
+ public String getTelegramName(final int uid) {
+ List<String> list = getJdbcTemplate().queryForList(
+ "SELECT tg_name FROM telegram WHERE user_id = ?",
+ String.class,
+ uid);
+
+ return list.isEmpty() ?
+ "" : list.get(0);
+ }
+
+ @Override
+ public Optional<Pair<String, String>> getVkTokens(final int uid) {
+ List<Optional<Pair<String, String>>> list = getJdbcTemplate().query(
+ "SELECT vk_id, access_token FROM vk WHERE user_id = ? AND crosspost = 1",
+ (rs, num) -> Optional.of(Pair.of(rs.getString(1), rs.getString(2))),
+ uid);
+
+ return list.isEmpty() ?
+ Optional.empty() : list.get(0);
+ }
+}