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 = 0; String uname = request.getParameter("uname"); if (uname == null) { uid = vuid; } else { if (UserQueries.checkUserNameValid(uname)) { com.juick.User u = UserQueries.getUserByNick(sql, uname); if (u != null && u.UID > 0) { uid = u.UID; } } } if (uid > 0) { ArrayList uids = UserQueries.getUserRead(sql, uid); if (uids.size() > 0) { ArrayList 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 = 0; String uname = request.getParameter("uname"); if (uname == null) { uid = vuid; } else { if (UserQueries.checkUserNameValid(uname)) { com.juick.User u = UserQueries.getUserByNick(sql, uname); if (u != null && u.UID > 0) { uid = u.UID; } } } if (uid > 0) { ArrayList uids = UserQueries.getUserReaders(sql, uid); if (uids.size() > 0) { ArrayList 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); } }