diff options
author | 2016-10-24 15:33:42 +0300 | |
---|---|---|
committer | 2016-10-24 15:36:33 +0300 | |
commit | fee6237f70338f2f960bc3dc614263e2db5dccef (patch) | |
tree | 95a6f38643ca3b381577510874571c2a1fd4d035 /juick-api/src/main/java/com/juick/api/Notifications.java | |
parent | 1a38addf7a4ab6186d97ea1ee71ed3889a5e6b08 (diff) |
api: notifications
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/Notifications.java')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/Notifications.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Notifications.java b/juick-api/src/main/java/com/juick/api/Notifications.java new file mode 100644 index 00000000..7cf27fc1 --- /dev/null +++ b/juick-api/src/main/java/com/juick/api/Notifications.java @@ -0,0 +1,43 @@ +package com.juick.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.juick.User; +import com.juick.server.PushQueries; +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 Notifications { + JdbcTemplate jdbc; + public Notifications(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); + return; + } + String type = request.getParameter("type"); + int uid = NumberUtils.toInt(request.getParameter("uid"), 0); + int mid = NumberUtils.toInt(request.getParameter("mid"), 0); + if (uid > 0) { + switch (type) { + case "gcm": + List<String> tokens = PushQueries.getAndroidRegID(jdbc, uid); + ObjectMapper mapper = new ObjectMapper(); + Main.replyJSON(request, response, mapper.writeValueAsString(tokens)); + } + + } + } +} |