diff options
author | Ugnich Anton | 2013-06-20 19:44:16 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-06-20 19:44:16 +0700 |
commit | 0dfa3b0cf640f4b95a3cdfdf8c32ae764d3ff5dd (patch) | |
tree | 60305d81cf32324dfdf7cb8934e0611deb098dd6 /src/java/com/juick/api/Users.java |
Initial commit
Diffstat (limited to 'src/java/com/juick/api/Users.java')
-rw-r--r-- | src/java/com/juick/api/Users.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/java/com/juick/api/Users.java b/src/java/com/juick/api/Users.java new file mode 100644 index 00000000..5810ddba --- /dev/null +++ b/src/java/com/juick/api/Users.java @@ -0,0 +1,70 @@ +package com.juick.api; + +import com.juick.server.UserQueries; +import java.io.IOException; +import java.sql.Connection; +import java.util.ArrayList; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author ugnich + */ +public class Users { + + Connection sql; + + public Users(Connection sql) { + this.sql = sql; + } + + public void doGetUserRead(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + int uid = vuid; + String paramUID = request.getParameter("user_id"); + if (paramUID != null) { + try { + uid = Integer.parseInt(paramUID); + } catch (NumberFormatException e) { + } + } + + if (uid > 0) { + ArrayList<Integer> uids = UserQueries.getUserRead(sql, vuid); + if (uids.size() > 0) { + ArrayList<com.juick.User> users = UserQueries.getUsersByID(sql, uids); + if (users.size() > 0) { + String json = com.juick.json.Users.arrayToString(users); + Main.replyJSON(request, response, json); + return; + } + } + } + response.sendError(404); + } + + public void doGetUserReaders(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + int uid = vuid; + String paramUID = request.getParameter("user_id"); + if (paramUID != null) { + try { + uid = Integer.parseInt(paramUID); + } catch (NumberFormatException e) { + } + } + + if (uid > 0) { + ArrayList<Integer> uids = UserQueries.getUserReaders(sql, vuid); + if (uids.size() > 0) { + ArrayList<com.juick.User> users = UserQueries.getUsersByID(sql, uids); + if (users.size() > 0) { + String json = com.juick.json.Users.arrayToString(users); + Main.replyJSON(request, response, json); + return; + } + } + } + response.sendError(404); + } +} |