diff options
author | 2016-11-13 21:21:45 +0700 | |
---|---|---|
committer | 2016-11-13 21:21:45 +0700 | |
commit | 6ba7eb5fe1384ec87cdd0031d185a9b26512a016 (patch) | |
tree | 1448ba6c8dda4302e3ad847cb085d49b8b054867 /server-core/src/main/java/com/juick/server/PrivacyQueries.java | |
parent | b75258ee5ed84510579050b5dba1edb904a09dfa (diff) |
server core module
Diffstat (limited to 'server-core/src/main/java/com/juick/server/PrivacyQueries.java')
-rw-r--r-- | server-core/src/main/java/com/juick/server/PrivacyQueries.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server-core/src/main/java/com/juick/server/PrivacyQueries.java b/server-core/src/main/java/com/juick/server/PrivacyQueries.java new file mode 100644 index 00000000..53b13505 --- /dev/null +++ b/server-core/src/main/java/com/juick/server/PrivacyQueries.java @@ -0,0 +1,32 @@ +package com.juick.server; + +import com.juick.Tag; +import com.juick.User; +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * Created by vitalyster on 19.10.2016. + */ +public class PrivacyQueries { + public enum PrivacyResult { + Removed, Added + } + public static PrivacyResult blacklistUser(JdbcTemplate jdbc, User user, User target) { + int result = jdbc.update("DELETE FROM bl_users WHERE user_id=? AND bl_user_id=?", user.getUID(), target.getUID()); + if (result > 0) { + return PrivacyResult.Removed; + } else { + jdbc.update("INSERT INTO bl_users(user_id,bl_user_id) VALUES (?,?)", user.getUID(), target.getUID()); + return PrivacyResult.Added; + } + } + public static PrivacyResult blacklistTag(JdbcTemplate jdbc, User user, Tag tag) { + int result = jdbc.update("DELETE FROM bl_tags WHERE user_id=? AND tag_id=?", user.getUID(), tag.TID); + if (result > 0) { + return PrivacyResult.Removed; + } else { + jdbc.update("INSERT INTO bl_tags(user_id,tag_id) VALUES (?,?)", user.getUID(), tag.TID); + return PrivacyResult.Added; + } + } +} |