♻️ No idea, but errors all gone

This commit is contained in:
2025-07-08 23:55:31 +08:00
parent 2c67472894
commit 63b2b989ba
74 changed files with 1551 additions and 1100 deletions

View File

@@ -1,5 +1,6 @@
using System.Globalization;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Services;
using DysonNetwork.Sphere.Localization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
@@ -11,7 +12,8 @@ namespace DysonNetwork.Sphere.Wallet;
public class PaymentService(
AppDatabase db,
WalletService wat,
DysonNetwork.Shared.Services.INotificationService nty,
INotificationService nty,
IAccountService acc,
IStringLocalizer<NotificationResource> localizer
)
{
@@ -196,10 +198,10 @@ public class PaymentService(
private async Task NotifyOrderPaid(Order order)
{
if (order.PayeeWallet is null) return;
var account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == order.PayeeWallet.AccountId);
var account = await acc.GetAccountById(order.PayeeWallet.AccountId);
if (account is null) return;
AccountService.SetCultureInfo(account);
// AccountService.SetCultureInfo(account);
// Due to ID is uuid, it longer than 8 words for sure
var readableOrderId = order.Id.ToString().Replace("-", "")[..8];

View File

@@ -5,11 +5,14 @@ using Quartz;
namespace DysonNetwork.Sphere.Wallet;
using DysonNetwork.Shared.Services;
public class SubscriptionRenewalJob(
AppDatabase db,
SubscriptionService subscriptionService,
PaymentService paymentService,
WalletService walletService,
IAccountProfileService accountProfileService,
ILogger<SubscriptionRenewalJob> logger
) : IJob
{
@@ -138,10 +141,7 @@ public class SubscriptionRenewalJob(
logger.LogInformation("Validating user stellar memberships...");
// Get all account IDs with StellarMembership
var accountsWithMemberships = await db.AccountProfiles
.Where(a => a.StellarMembership != null)
.Select(a => new { a.Id, a.StellarMembership })
.ToListAsync();
var accountsWithMemberships = await accountProfileService.GetAccountsWithStellarMembershipAsync();
logger.LogInformation("Found {Count} accounts with stellar memberships to validate",
accountsWithMemberships.Count);
@@ -187,11 +187,7 @@ public class SubscriptionRenewalJob(
}
// Update all accounts in a single batch operation
var updatedCount = await db.AccountProfiles
.Where(a => accountIdsToUpdate.Contains(a.Id))
.ExecuteUpdateAsync(s => s
.SetProperty(a => a.StellarMembership, p => null)
);
var updatedCount = await accountProfileService.ClearStellarMembershipsAsync(accountIdsToUpdate);
logger.LogInformation("Updated {Count} accounts with expired/invalid stellar memberships", updatedCount);
}

View File

@@ -1,5 +1,6 @@
using System.Text.Json;
using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Localization;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Services;
using DysonNetwork.Sphere.Localization;
@@ -14,8 +15,9 @@ namespace DysonNetwork.Sphere.Wallet;
public class SubscriptionService(
AppDatabase db,
PaymentService payment,
DysonNetwork.Shared.Services.IAccountService account,
DysonNetwork.Shared.Services.INotificationService nty,
IAccountService accounts,
IAccountProfileService profiles,
INotificationService nty,
IStringLocalizer<NotificationResource> localizer,
IConfiguration configuration,
ICacheService cache,
@@ -23,7 +25,7 @@ public class SubscriptionService(
)
{
public async Task<Subscription> CreateSubscriptionAsync(
Shared.Models.Account account,
Account account,
string identifier,
string paymentMethod,
PaymentDetails paymentDetails,
@@ -57,9 +59,7 @@ public class SubscriptionService(
if (subscriptionInfo.RequiredLevel > 0)
{
var profile = await db.AccountProfiles
.Where(p => p.AccountId == account.Id)
.FirstOrDefaultAsync();
var profile = await profiles.GetAccountProfileByIdAsync(account.Id);
if (profile is null) throw new InvalidOperationException("Account profile was not found.");
if (profile.Level < subscriptionInfo.RequiredLevel)
throw new InvalidOperationException(
@@ -141,7 +141,7 @@ public class SubscriptionService(
if (!string.IsNullOrEmpty(provider))
account = await accounts.LookupAccountByConnection(order.AccountId, provider);
else if (Guid.TryParse(order.AccountId, out var accountId))
account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == accountId);
account = await accounts.GetAccountById(accountId);
if (account is null)
throw new InvalidOperationException($"Account was not found with identifier {order.AccountId}");
@@ -302,9 +302,7 @@ public class SubscriptionService(
if (subscription.Identifier.StartsWith(SubscriptionType.StellarProgram))
{
await db.AccountProfiles
.Where(a => a.AccountId == subscription.AccountId)
.ExecuteUpdateAsync(s => s.SetProperty(a => a.StellarMembership, subscription.ToReference()));
await profiles.UpdateStellarMembershipAsync(subscription.AccountId, subscription.ToReference());
}
await NotifySubscriptionBegun(subscription);
@@ -348,10 +346,10 @@ public class SubscriptionService(
private async Task NotifySubscriptionBegun(Subscription subscription)
{
var account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == subscription.AccountId);
var account = await accounts.GetAccountById(subscription.AccountId);
if (account is null) return;
AccountService.SetCultureInfo(account);
CultureInfoService.SetCultureInfo(account);
var humanReadableName =
SubscriptionTypeData.SubscriptionHumanReadable.TryGetValue(subscription.Identifier, out var humanReadable)

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Permission;
using DysonNetwork.Shared.Permission;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@@ -75,7 +75,7 @@ public class WalletController(AppDatabase db, WalletService ws, PaymentService p
[HttpPost("balance")]
[Authorize]
[RequiredPermissionAttribute("maintenance", "wallets.balance.modify")]
[DysonNetwork.Shared.Permission.RequiredPermission("maintenance", "wallets.balance.modify")]
public async Task<ActionResult<Transaction>> ModifyWalletBalance([FromBody] WalletBalanceRequest request)
{
var wallet = await ws.GetWalletAsync(request.AccountId);