From fb33f4abc9b33156a3be1979f7796068a5efebfc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 10 Dec 2024 00:02:31 +0800 Subject: [PATCH] :bug: Trying to fix get featured posts failed --- pkg/internal/services/featured.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/internal/services/featured.go b/pkg/internal/services/featured.go index 4a221ab..6d0931a 100644 --- a/pkg/internal/services/featured.go +++ b/pkg/internal/services/featured.go @@ -18,11 +18,11 @@ func GetFeaturedPosts(count int) ([]models.Post, error) { var posts []models.Post if err := database.C.Raw(` - SELECT p.* + SELECT p.*, t.social_points FROM posts p JOIN ( - SELECT - post_id, + SELECT + post_id, SUM(CASE WHEN attitude = 1 THEN 1 ELSE 0 END) - SUM(CASE WHEN attitude = 2 THEN 1 ELSE 0 END) AS social_points FROM reactions @@ -32,7 +32,7 @@ func GetFeaturedPosts(count int) ([]models.Post, error) { LIMIT ? ) t ON p.id = t.post_id ORDER BY t.social_points DESC, p.published_at DESC - `, deadline, count).Scan(&posts).Error; err != nil { + `, deadline, count).Scan(&posts).Error; err != nil { return posts, err }