diff options
author | Vitaly Takmazov | 2018-02-25 09:04:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-21 11:45:00 +0300 |
commit | 9b201b07dc6caa147ea79b359e448f2649353039 (patch) | |
tree | 02f732c7ba6e249a4b65998c4584c14d1c0cb91c /juick-server-jdbc/src | |
parent | 1e4198d2aad02eca56157fcd24425a1eaa6041ee (diff) |
xmpp: recommend command
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java | 15 | ||||
-rw-r--r-- | juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java | 4 |
2 files changed, 13 insertions, 6 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java index 87ab35f3..4398259c 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -230,12 +230,19 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional @Override - public boolean recommendMessage(final int mid, final int vuid) { + public RecommendStatus recommendMessage(final int mid, final int vuid) { int wasDeleted = getJdbcTemplate() .update("DELETE FROM favorites WHERE user_id=? AND message_id=?", vuid, mid); - return wasDeleted == 0 - && getJdbcTemplate() - .update("INSERT INTO favorites(user_id, message_id, ts) VALUES (?, ?, NOW())", vuid, mid) == 1; + if (wasDeleted > 0) { + return RecommendStatus.Deleted; + } else { + boolean wasAdded = getJdbcTemplate() + .update("INSERT INTO favorites(user_id, message_id, ts) VALUES (?, ?, NOW())", vuid, mid) == 1; + if (wasAdded) { + return RecommendStatus.Added; + } + } + return RecommendStatus.Error; } @Transactional(readOnly = true) diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index 57e0970a..7b321496 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -102,9 +102,9 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { assertThat(messagesService.getMyFeed(freefdId, 0, true).size(), equalTo(3)); assertThat(messagesService.getMyFeed(freefdId, mid2, true).size(), equalTo(1)); assertThat(messagesService.getMyFeed(freefdId, mid, false).size(), equalTo(0)); - assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(true)); + assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(MessagesService.RecommendStatus.Added)); assertThat(messagesService.getMessage(mid).getLikes(), equalTo(1)); - assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(false)); + assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(MessagesService.RecommendStatus.Deleted)); assertThat(messagesService.getMessage(mid).getLikes(), equalTo(0)); assertThat(messagesService.getAll(ugnichId, 0).size(), equalTo(3)); |