🐛 Prevent user from creating boost on same destination

This commit is contained in:
LittleSheep 2024-12-29 12:24:56 +08:00
parent a58f44d50e
commit 78e554577e

View File

@ -66,7 +66,12 @@ func GetBoostByID(id uint) (models.AttachmentBoost, error) {
} }
func CreateBoost(user *sec.UserInfo, source models.Attachment, destination int) (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, Status: models.BoostStatusPending,
Destination: destination, Destination: destination,
AttachmentID: source.ID, AttachmentID: source.ID,