From 1a38addf7a4ab6186d97ea1ee71ed3889a5e6b08 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 24 Oct 2016 15:01:34 +0300 Subject: api: subscriptions --- juick-api/src/main/java/com/juick/api/Main.java | 4 +++ .../src/main/java/com/juick/api/Subscriptions.java | 35 ++++++++++++++++++++++ .../com/juick/ws/components/PushComponent.java | 2 -- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 juick-api/src/main/java/com/juick/api/Subscriptions.java diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java index cad991ef..3bd1e750 100644 --- a/juick-api/src/main/java/com/juick/api/Main.java +++ b/juick-api/src/main/java/com/juick/api/Main.java @@ -70,6 +70,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { Users users; PM pm; Others others; + Subscriptions subscriptions; TelegramBotHook tgb; SkypeEndpoint sep; @@ -90,6 +91,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { users = new Users(jdbc); pm = new PM(jdbc); others = new Others(jdbc); + subscriptions = new Subscriptions(jdbc); tgb = new TelegramBotHook(jdbc, conf.getProperty("telegram_token", "")); sep = new SkypeEndpoint(); setupXmppComponent(conf.getProperty("xmpp_host", "localhost"), Integer.parseInt(conf.getProperty("xmpp_port", "5347")), @@ -183,6 +185,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { messages.doSetPopular(request, response, xmpp); } else if (uri.equals("/messages/set_privacy") && vuid > 0) { messages.doSetPrivacy(request, response, xmpp, vuid); + } else if (uri.equals("/subscriptions")) { + subscriptions.doGet(request, response, vuid); } else { response.sendError(404); } diff --git a/juick-api/src/main/java/com/juick/api/Subscriptions.java b/juick-api/src/main/java/com/juick/api/Subscriptions.java new file mode 100644 index 00000000..49990080 --- /dev/null +++ b/juick-api/src/main/java/com/juick/api/Subscriptions.java @@ -0,0 +1,35 @@ +package com.juick.api; + +import com.juick.User; +import com.juick.json.UserSerializer; +import com.juick.server.SubscriptionsQueries; +import com.juick.server.UserQueries; +import org.apache.commons.lang3.math.NumberUtils; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +/** + * Created by vitalyster on 24.10.2016. + */ +public class Subscriptions { + JdbcTemplate jdbc; + + public Subscriptions(JdbcTemplate jdbc) { + this.jdbc = jdbc; + } + public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException { + User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User()); + if (!(visitor.getUID() > 0) && !(visitor.getUName().equals("juick"))) { + response.sendError(403); + } + int uid = NumberUtils.toInt(request.getParameter("uid"), 0); + int mid = NumberUtils.toInt(request.getParameter("mid"), 0); + List users = SubscriptionsQueries.getSubscribedUsers(jdbc, uid, mid); + UserSerializer userSerializer = new UserSerializer(); + Main.replyJSON(request, response, userSerializer.serializeList(users)); + } +} diff --git a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java index 5c4fc969..54dd21de 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java @@ -49,8 +49,6 @@ import org.json.JSONObject; import org.springframework.beans.factory.DisposableBean; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.inject.Inject; -- cgit v1.2.3