From 30068e18a3d8ae37b509f5cd766515735a818692 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 15 Jan 2016 15:54:04 +0300 Subject: update core --- src/main/java/com/juick/api/Messages.java | 23 ++++++++++++++++------- src/main/java/com/juick/api/Others.java | 4 +++- src/main/java/com/juick/api/PM.java | 16 ++++++++++------ src/main/java/com/juick/api/Users.java | 20 +++++++++++++------- src/test/java/com/juick/tests/ApiTests.java | 6 +++--- 5 files changed, 45 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java index fb9be051..e242d05b 100644 --- a/src/main/java/com/juick/api/Messages.java +++ b/src/main/java/com/juick/api/Messages.java @@ -53,7 +53,9 @@ public class Messages { this.sql = sql; } - public void doGetHome(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetHome(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); List mids = MessagesQueries.getMyFeed(sql, vuid, before_mid); @@ -70,7 +72,8 @@ public class Messages { } } - public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) + public void doGet(HttpServletRequest request, + HttpServletResponse response, int vuid) throws ServletException, IOException { User user = UserQueries.getUserByName(sql, request.getParameter("uname")); int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); @@ -81,7 +84,9 @@ public class Messages { } - public void doGetRecommended(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetRecommended(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); List mids = MessagesQueries.getUserRecommendations(sql, vuid, before_mid); @@ -98,17 +103,21 @@ public class Messages { } } - public void doSetPrivacy(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException { + public void doSetPrivacy(HttpServletRequest request, + HttpServletResponse response, Stream xmpp, int vuid) + throws ServletException, IOException { int mid = Utils.parseInt(request.getParameter("mid"), 0); com.juick.User user = MessagesQueries.getMessageAuthor(sql, mid); - if (user != null && user.UID == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) { + if (user != null && user.getUID() == vuid && MessagesQueries.setMessagePrivacy(sql, mid)) { Main.replyJSON(request, response, "{\"status\":\"ok\"}"); } else { response.sendError(400); } } - public void doSetPopular(HttpServletRequest request, HttpServletResponse response, Stream xmpp) throws ServletException, IOException { + public void doSetPopular(HttpServletRequest request, + HttpServletResponse response, Stream xmpp) + throws ServletException, IOException { int mid = Utils.parseInt(request.getParameter("mid"), 0); int popular = Utils.parseInt(request.getParameter("popular"), 0); @@ -123,7 +132,7 @@ public class Messages { msg.from = new JID("juick", "juick.com", null); msg.to = new JID(null, "crosspost.juick.com", null); JuickMessage jmsg = new JuickMessage(m); - jmsg.User.UID = 11574; + jmsg.setUser(UserQueries.getUserByUID(sql, 11574)); msg.childs.add(jmsg); msg.to.Username = "twitter"; diff --git a/src/main/java/com/juick/api/Others.java b/src/main/java/com/juick/api/Others.java index 3c8d4a96..12849f90 100644 --- a/src/main/java/com/juick/api/Others.java +++ b/src/main/java/com/juick/api/Others.java @@ -26,7 +26,9 @@ public class Others { this.sql = sql; } - public void doGetGroupsPMs(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetGroupsPMs(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { int cnt = 5; try { String cntStr = request.getParameter("cnt"); diff --git a/src/main/java/com/juick/api/PM.java b/src/main/java/com/juick/api/PM.java index 01a5669a..3ca9eada 100644 --- a/src/main/java/com/juick/api/PM.java +++ b/src/main/java/com/juick/api/PM.java @@ -29,7 +29,9 @@ public class PM { this.sql = sql; } - public void doGetPM(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetPM(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { String uname = request.getParameter("uname"); int uid = 0; if (uname != null && uname.matches("^[a-zA-Z0-9\\-]{2,16}$")) { @@ -50,7 +52,9 @@ public class PM { } } - public void doPostPM(HttpServletRequest request, HttpServletResponse response, Stream xmpp, int vuid) throws ServletException, IOException { + public void doPostPM(HttpServletRequest request, + HttpServletResponse response, Stream xmpp, int vuid) + throws ServletException, IOException { String uname = request.getParameter("uname"); int uid = 0; if (UserQueries.checkUserNameValid(uname)) { @@ -73,8 +77,8 @@ public class PM { msg.from = new JID("juick", "juick.com", null); msg.to = new JID(Integer.toString(uid), "push.juick.com", null); JuickMessage jmsg = new JuickMessage(); - jmsg.User = UserQueries.getUserByUID(sql, vuid); - jmsg.Text = body; + jmsg.setUser(UserQueries.getUserByUID(sql, vuid)); + jmsg.setText(body); msg.childs.add(jmsg); xmpp.send(msg); @@ -89,11 +93,11 @@ public class PM { mm.to = new JID(jid); mm.type = Message.Type.chat; if (PMQueries.havePMinRoster(sql, vuid, jid)) { - mm.from = new JID(jmsg.User.UName, "juick.com", "Juick"); + mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick"); mm.body = body; } else { mm.from = new JID("juick", "juick.com", "Juick"); - mm.body = "Private message from @" + jmsg.User.UName + ":\n" + body; + mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + body; } xmpp.send(mm); } diff --git a/src/main/java/com/juick/api/Users.java b/src/main/java/com/juick/api/Users.java index d3818a5a..57f8c4b9 100644 --- a/src/main/java/com/juick/api/Users.java +++ b/src/main/java/com/juick/api/Users.java @@ -27,7 +27,9 @@ public class Users { this.sql = sql; } - public void doGetUsers(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetUsers(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { List users = new ArrayList<>(); String punames[] = request.getParameterValues("uname"); @@ -66,7 +68,9 @@ public class Users { } } - public void doGetUserRead(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetUserRead(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { int uid = 0; String uname = request.getParameter("uname"); if (uname == null) { @@ -74,8 +78,8 @@ public class Users { } else { if (UserQueries.checkUserNameValid(uname)) { com.juick.User u = UserQueries.getUserByName(sql, uname); - if (u != null && u.UID > 0) { - uid = u.UID; + if (u != null && u.getUID() > 0) { + uid = u.getUID(); } } } @@ -94,7 +98,9 @@ public class Users { response.sendError(404); } - public void doGetUserReaders(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + public void doGetUserReaders(HttpServletRequest request, + HttpServletResponse response, int vuid) + throws ServletException, IOException { int uid = 0; String uname = request.getParameter("uname"); if (uname == null) { @@ -102,8 +108,8 @@ public class Users { } else { if (UserQueries.checkUserNameValid(uname)) { com.juick.User u = UserQueries.getUserByName(sql, uname); - if (u != null && u.UID > 0) { - uid = u.UID; + if (u != null && u.getUID() > 0) { + uid = u.getUID(); } } } diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java index b679f528..046077ef 100644 --- a/src/test/java/com/juick/tests/ApiTests.java +++ b/src/test/java/com/juick/tests/ApiTests.java @@ -38,14 +38,14 @@ public class ApiTests { @Test public void userTests() { User user = UserQueries.getUserByUID(jdbc, 3694); - Assert.assertEquals("it should be me", "vt", user.UName); + Assert.assertEquals("it should be me", "vt", user.getUName()); } @Test public void messageTests() { Message msg = MessagesQueries.getMessage(jdbc, 2817722); - User ugnich = msg.User; - Assert.assertEquals("ugnich", ugnich.UName); + User ugnich = msg.getUser(); + Assert.assertEquals("ugnich", ugnich.getUName()); Assert.assertEquals("Microsoft", msg.Tags.get(0)); } } -- cgit v1.2.3