From 78e554577ed4e7aaac309b339e57c09de63b8c62 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 29 Dec 2024 12:24:56 +0800 Subject: [PATCH] :bug: Prevent user from creating boost on same destination --- pkg/internal/services/boost.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/internal/services/boost.go b/pkg/internal/services/boost.go index c76297e..2b3dedc 100644 --- a/pkg/internal/services/boost.go +++ b/pkg/internal/services/boost.go @@ -66,7 +66,12 @@ func GetBoostByID(id uint) (models.AttachmentBoost, error) { } func CreateBoost(user *sec.UserInfo, source models.Attachment, destination int) (models.AttachmentBoost, error) { - boost := models.AttachmentBoost{ + var boost models.AttachmentBoost + if err := database.C.Where("attachment_id = ? AND destination = ?", source.ID, destination).First(&boost); err == nil { + return boost, fmt.Errorf("boost already exists") + } + + boost = models.AttachmentBoost{ Status: models.BoostStatusPending, Destination: destination, AttachmentID: source.ID,