aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/PrivacyQueries.java
blob: 40fc82c4e5aa8367c540c9f629073db515b4254e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
        }
    }
}