diff options
author | 2016-12-13 15:41:37 +0300 | |
---|---|---|
committer | 2016-12-13 15:42:14 +0300 | |
commit | dd4b8ff44e11a5b4734e428e3a7153eb1b89a825 (patch) | |
tree | ab307ddc31a2b8dcc52260e5bdd4fffe42bbd0c8 /juick-server/src/main | |
parent | a165d44d8a2a8ffc5deaa29f40381ad5ea7b3483 (diff) |
juick-rss: webmvc port WIP
Diffstat (limited to 'juick-server/src/main')
3 files changed, 109 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/helpers/ResponseReply.java b/juick-server/src/main/java/com/juick/server/helpers/ResponseReply.java new file mode 100644 index 00000000..f941c743 --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/helpers/ResponseReply.java @@ -0,0 +1,72 @@ +package com.juick.server.helpers; + +import java.util.Date; + +/** + * Created by vitalyster on 13.12.2016. + */ +public class ResponseReply { + private String muname; + private int mid; + private int rid; + private String uname; + private String description; + private Date pubDate; + private String attachmentType; + + public String getMuname() { + return muname; + } + + public void setMuname(String muname) { + this.muname = muname; + } + + public int getMid() { + return mid; + } + + public void setMid(int mid) { + this.mid = mid; + } + + public int getRid() { + return rid; + } + + public void setRid(int rid) { + this.rid = rid; + } + + public String getUname() { + return uname; + } + + public void setUname(String uname) { + this.uname = uname; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getPubDate() { + return pubDate; + } + + public void setPubDate(Date pubDate) { + this.pubDate = pubDate; + } + + public String getAttachmentType() { + return attachmentType; + } + + public void setAttachmentType(String attachmentType) { + this.attachmentType = attachmentType; + } +} diff --git a/juick-server/src/main/java/com/juick/service/MessagesService.java b/juick-server/src/main/java/com/juick/service/MessagesService.java index f7175967..8cb0782f 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesService.java +++ b/juick-server/src/main/java/com/juick/service/MessagesService.java @@ -1,6 +1,8 @@ package com.juick.service; +import com.juick.Message; import com.juick.User; +import com.juick.server.helpers.ResponseReply; import org.springframework.jdbc.core.JdbcTemplate; import java.util.Collection; @@ -75,4 +77,8 @@ public interface MessagesService { boolean setMessagePrivacy(int mid); boolean deleteMessage(int uid, int mid); + + List<Integer> getLastMessages(int hours); + + List<ResponseReply> getLastReplies(int hours); } diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java index d7c1d51b..88167be8 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -4,6 +4,7 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.server.helpers.PrivacyOpts; +import com.juick.server.helpers.ResponseReply; import com.juick.service.search.SearchService; import com.juick.util.MessageUtils; import org.apache.commons.collections4.CollectionUtils; @@ -739,4 +740,34 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ } return false; } + + @Transactional(readOnly = true) + @Override + public List<Integer> getLastMessages(int hours) { + return getJdbcTemplate().queryForList("SELECT message_id FROM messages WHERE messages.ts>TIMESTAMPADD(HOUR,?,NOW())", + Integer.class, -hours); + + } + + @Transactional(readOnly = true) + @Override + public List<ResponseReply> getLastReplies(int hours) { + return getJdbcTemplate().query("SELECT users2.nick,replies.message_id,replies.reply_id," + + "users.nick,replies.txt," + + "replies.ts,replies.attach,replies.ts+0 " + + "FROM ((replies INNER JOIN users ON replies.user_id=users.id) " + + "INNER JOIN messages ON replies.message_id=messages.message_id) " + + "INNER JOIN users AS users2 ON messages.user_id=users2.id " + + "WHERE replies.ts>TIMESTAMPADD(HOUR,?,NOW()) AND messages.privacy>0", (rs, rowNum) -> { + ResponseReply reply = new ResponseReply(); + reply.setMuname(rs.getString(1)); + reply.setMid(rs.getInt(2)); + reply.setRid(rs.getInt(3)); + reply.setUname(rs.getString(4)); + reply.setDescription(rs.getString(5)); + reply.setPubDate(rs.getTimestamp(6)); + reply.setAttachmentType(rs.getString(7)); + return reply; + }, -hours); + } } |