From 7f8521bb40ea35bd79ce6d9c8587d756ed81093c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 16 Oct 2025 13:13:08 +0800 Subject: [PATCH] :necktie: Optimize subscriptions logic --- .../Wallet/SubscriptionGiftController.cs | 3 ++- DysonNetwork.Pass/Wallet/SubscriptionService.cs | 11 +++++++++++ .../Autocompletion/AutocompletionService.cs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/DysonNetwork.Pass/Wallet/SubscriptionGiftController.cs b/DysonNetwork.Pass/Wallet/SubscriptionGiftController.cs index 98f3df8..6e77d02 100644 --- a/DysonNetwork.Pass/Wallet/SubscriptionGiftController.cs +++ b/DysonNetwork.Pass/Wallet/SubscriptionGiftController.cs @@ -197,7 +197,8 @@ public class SubscriptionGiftController( if (currentUser.Profile.Level < MinimumAccountLevel) { - return StatusCode(403, "Account level must be at least 60 to purchase a gift."); + if (currentUser.PerkSubscription is null) + return StatusCode(403, "Account level must be at least 60 or a member of the Stellar Program to purchase a gift."); } Duration? giftDuration = null; diff --git a/DysonNetwork.Pass/Wallet/SubscriptionService.cs b/DysonNetwork.Pass/Wallet/SubscriptionService.cs index 6df8404..9e3cfbb 100644 --- a/DysonNetwork.Pass/Wallet/SubscriptionService.cs +++ b/DysonNetwork.Pass/Wallet/SubscriptionService.cs @@ -250,6 +250,14 @@ public class SubscriptionService( : null; if (subscriptionInfo is null) throw new InvalidOperationException("No matching subscription found."); + if (subscriptionInfo.RequiredLevel > 0) + { + var profile = await db.AccountProfiles.FirstOrDefaultAsync(p => p.AccountId == subscription.AccountId); + if (profile is null) throw new InvalidOperationException("Account must have a profile"); + if (profile.Level < subscriptionInfo.RequiredLevel) + throw new InvalidOperationException("Account level must be at least 60 to purchase a gift."); + } + return await payment.CreateOrderAsync( null, subscriptionInfo.Currency, @@ -684,6 +692,9 @@ public class SubscriptionService( if (now > gift.ExpiresAt) throw new InvalidOperationException("Gift has expired."); + if (gift.GifterId == redeemer.Id) + throw new InvalidOperationException("You cannot redeem your own gift."); + // Validate redeemer permissions if (!gift.IsOpenGift && gift.RecipientId != redeemer.Id) throw new InvalidOperationException("This gift is not intended for you."); diff --git a/DysonNetwork.Sphere/Autocompletion/AutocompletionService.cs b/DysonNetwork.Sphere/Autocompletion/AutocompletionService.cs index b88e7ee..1da9380 100644 --- a/DysonNetwork.Sphere/Autocompletion/AutocompletionService.cs +++ b/DysonNetwork.Sphere/Autocompletion/AutocompletionService.cs @@ -16,7 +16,7 @@ public class AutocompletionService(AppDatabase db, AccountClientHelper accountsH var afterAt = content[1..]; string type; string query; - bool hadSlash = afterAt.Contains('/'); + var hadSlash = afterAt.Contains('/'); if (hadSlash) { var parts = afterAt.Split('/', 2);