From 86cdf28b22ed3da1d4feb184def8758a0248587a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 17 Sep 2024 01:43:01 +0800 Subject: [PATCH] :bug: Fix determine subscription has or not --- pkg/internal/services/subscriptions.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/internal/services/subscriptions.go b/pkg/internal/services/subscriptions.go index ac14a83..cf69323 100644 --- a/pkg/internal/services/subscriptions.go +++ b/pkg/internal/services/subscriptions.go @@ -50,7 +50,7 @@ func GetSubscriptionOnCategory(user models.Account, target models.Category) (*mo func SubscribeToUser(user models.Account, target models.Account) (models.Subscription, error) { var subscription models.Subscription if err := database.C.Where("follower_id = ? AND account_id = ?", user.ID, target.ID).First(&subscription).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if !errors.Is(err, gorm.ErrRecordNotFound) { return subscription, fmt.Errorf("subscription already exists") } return subscription, fmt.Errorf("unable to check subscription is exists or not: %v", err) @@ -68,7 +68,7 @@ func SubscribeToUser(user models.Account, target models.Account) (models.Subscri func SubscribeToTag(user models.Account, target models.Tag) (models.Subscription, error) { var subscription models.Subscription if err := database.C.Where("follower_id = ? AND tag_id = ?", user.ID, target.ID).First(&subscription).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if !errors.Is(err, gorm.ErrRecordNotFound) { return subscription, fmt.Errorf("subscription already exists") } return subscription, fmt.Errorf("unable to check subscription is exists or not: %v", err) @@ -86,7 +86,7 @@ func SubscribeToTag(user models.Account, target models.Tag) (models.Subscription func SubscribeToCategory(user models.Account, target models.Category) (models.Subscription, error) { var subscription models.Subscription if err := database.C.Where("follower_id = ? AND category_id = ?", user.ID, target.ID).First(&subscription).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if !errors.Is(err, gorm.ErrRecordNotFound) { return subscription, fmt.Errorf("subscription already exists") } return subscription, fmt.Errorf("unable to check subscription is exists or not: %v", err)