From 9b201b07dc6caa147ea79b359e448f2649353039 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 25 Feb 2018 09:04:17 +0300 Subject: xmpp: recommend command --- .../main/java/com/juick/service/MessagesServiceImpl.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'juick-server-jdbc/src/main/java/com/juick') 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) -- cgit v1.2.3