From d176163012cae7c5bcc59127365bf7dd73ea1192 Mon Sep 17 00:00:00 2001 From: slashlight Date: Fri, 20 Dec 2024 22:48:06 +0300 Subject: [PATCH] bugfix: fixed get all friends --- internal/profile/repository/QueryConsts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/profile/repository/QueryConsts.go b/internal/profile/repository/QueryConsts.go index bfa5966a..904335e4 100644 --- a/internal/profile/repository/QueryConsts.go +++ b/internal/profile/repository/QueryConsts.go @@ -8,7 +8,7 @@ const ( GetProfileByID = "SELECT profile.id, first_name, last_name, bio, avatar FROM profile WHERE profile.id = $1 LIMIT 1;" GetStatus = "SELECT status FROM friend WHERE (sender = $1 AND receiver = $2) LIMIT 1" - GetAllProfilesBatch = "WITH friends AS (SELECT sender AS friend FROM friend WHERE (receiver = $1 AND status = 0) UNION SELECT receiver AS friend FROM friend WHERE (sender = $1 AND status = 0)), subscriptions AS (SELECT sender AS subscription FROM friend WHERE (receiver = $1 AND status = -1) UNION SELECT receiver AS subscriber FROM friend WHERE (sender = $1 AND status = 1)) SELECT p.id, first_name, last_name, avatar FROM profile p WHERE p.id <> $1 AND p.id > $2 AND p.id NOT IN (SELECT friend FROM friends) AND p.id NOT IN (SELECT subscription FROM subscriptions) ORDER BY p.id LIMIT $3;" + GetAllProfilesBatch = "WITH friends AS (SELECT sender AS friend FROM friend WHERE (receiver = $1 AND status = 0) UNION SELECT receiver AS friend FROM friend WHERE (sender = $1 AND status = 0)), subscriptions AS (SELECT sender AS subscription FROM friend WHERE (receiver = $1 AND status = -1) UNION SELECT receiver AS subscription FROM friend WHERE (sender = $1 AND status = 1)), subscribers AS (SELECT sender AS subscriber FROM friend WHERE (receiver = $1 AND status = 1) UNION SELECT receiver AS subscriber FROM friend WHERE (sender = $1 AND status = -1)) SELECT p.id, first_name, last_name, avatar FROM profile p WHERE p.id <> $1 AND p.id > $2 AND p.id NOT IN (SELECT friend FROM friends) AND p.id NOT IN (SELECT subscription FROM subscriptions) AND p.id NOT IN (SELECT subscriber FROM subscribers) ORDER BY p.id LIMIT $3;" UpdateProfile = "UPDATE profile SET first_name = $1, last_name = $2, bio = $3 WHERE id = $4;" UpdateProfileAvatar = "UPDATE profile SET avatar = $2, first_name = $3, last_name = $4, bio = $5 WHERE id = $1;" DeleteProfile = "DELETE FROM profile WHERE id = $1;"