♻️ Splitted wallet service
This commit is contained in:
@@ -2,7 +2,6 @@ using System.ComponentModel.DataAnnotations;
|
||||
using DysonNetwork.Pass.Affiliation;
|
||||
using DysonNetwork.Pass.Auth;
|
||||
using DysonNetwork.Pass.Credit;
|
||||
using DysonNetwork.Pass.Wallet;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Geometry;
|
||||
using DysonNetwork.Shared.Models;
|
||||
@@ -20,7 +19,6 @@ public class AccountController(
|
||||
AppDatabase db,
|
||||
AuthService auth,
|
||||
AccountService accounts,
|
||||
SubscriptionService subscriptions,
|
||||
AccountEventService events,
|
||||
SocialCreditService socialCreditService,
|
||||
AffiliationSpellService ars,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DysonNetwork.Pass.Permission;
|
||||
using DysonNetwork.Pass.Wallet;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Networking;
|
||||
@@ -20,7 +19,6 @@ namespace DysonNetwork.Pass.Account;
|
||||
public class AccountCurrentController(
|
||||
AppDatabase db,
|
||||
AccountService accounts,
|
||||
SubscriptionService subscriptions,
|
||||
AccountEventService events,
|
||||
AuthService auth,
|
||||
FileService.FileServiceClient files,
|
||||
@@ -41,9 +39,6 @@ public class AccountCurrentController(
|
||||
.Where(e => e.Id == userId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var perk = await subscriptions.GetPerkSubscriptionAsync(account!.Id);
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
return Ok(account);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using DysonNetwork.Pass.Wallet;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
@@ -14,11 +13,9 @@ namespace DysonNetwork.Pass.Account;
|
||||
|
||||
public class AccountEventService(
|
||||
AppDatabase db,
|
||||
Wallet.PaymentService payment,
|
||||
ICacheService cache,
|
||||
IStringLocalizer<Localization.AccountEventResource> localizer,
|
||||
RingService.RingServiceClient pusher,
|
||||
SubscriptionService subscriptions,
|
||||
Pass.Leveling.ExperienceService experienceService,
|
||||
INatsConnection nats
|
||||
)
|
||||
@@ -234,9 +231,6 @@ public class AccountEventService(
|
||||
|
||||
public async Task<bool> CheckInDailyDoAskCaptcha(SnAccount user)
|
||||
{
|
||||
var perkSubscription = await subscriptions.GetPerkSubscriptionAsync(user.Id);
|
||||
if (perkSubscription is not null) return false;
|
||||
|
||||
var cacheKey = $"{CaptchaCacheKey}{user.Id}";
|
||||
var needsCaptcha = await cache.GetAsync<bool?>(cacheKey);
|
||||
if (needsCaptcha is not null)
|
||||
@@ -426,22 +420,6 @@ public class AccountEventService(
|
||||
CreatedAt = backdated ?? SystemClock.Instance.GetCurrentInstant(),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
if (result.RewardPoints.HasValue)
|
||||
await payment.CreateTransactionWithAccountAsync(
|
||||
null,
|
||||
user.Id,
|
||||
WalletCurrency.SourcePoint,
|
||||
result.RewardPoints.Value,
|
||||
$"Check-in reward on {now:yyyy/MM/dd}"
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result.RewardPoints = null;
|
||||
}
|
||||
|
||||
db.AccountCheckInResults.Add(result);
|
||||
await db.SaveChangesAsync(); // Remember to save changes to the database
|
||||
if (result.RewardExperience is not null)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using DysonNetwork.Pass.Credit;
|
||||
using DysonNetwork.Pass.Wallet;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Networking;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -11,7 +10,6 @@ namespace DysonNetwork.Pass.Account;
|
||||
[Route("/api/accounts")]
|
||||
public class AccountPublicController(
|
||||
AppDatabase db,
|
||||
SubscriptionService subscriptions,
|
||||
SocialCreditService socialCreditService
|
||||
) : ControllerBase
|
||||
{
|
||||
@@ -28,9 +26,6 @@ public class AccountPublicController(
|
||||
.FirstOrDefaultAsync();
|
||||
if (account is null) return NotFound(ApiError.NotFound(name, traceId: HttpContext.TraceIdentifier));
|
||||
|
||||
var perk = await subscriptions.GetPerkSubscriptionAsync(account.Id);
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using DysonNetwork.Pass.Wallet;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
@@ -11,7 +10,6 @@ public class AccountServiceGrpc(
|
||||
AppDatabase db,
|
||||
AccountEventService accountEvents,
|
||||
RelationshipService relationships,
|
||||
SubscriptionService subscriptions,
|
||||
ILogger<AccountServiceGrpc> logger
|
||||
)
|
||||
: Shared.Proto.AccountService.AccountServiceBase
|
||||
@@ -35,9 +33,6 @@ public class AccountServiceGrpc(
|
||||
if (account == null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, $"Account {request.Id} not found"));
|
||||
|
||||
var perk = await subscriptions.GetPerkSubscriptionAsync(account.Id);
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
return account.ToProtoValue();
|
||||
}
|
||||
|
||||
@@ -56,9 +51,6 @@ public class AccountServiceGrpc(
|
||||
throw new RpcException(new Grpc.Core.Status(StatusCode.NotFound,
|
||||
$"Account with automated ID {request.AutomatedId} not found"));
|
||||
|
||||
var perk = await subscriptions.GetPerkSubscriptionAsync(account.Id);
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
return account.ToProtoValue();
|
||||
}
|
||||
|
||||
@@ -77,13 +69,6 @@ public class AccountServiceGrpc(
|
||||
.Include(a => a.Profile)
|
||||
.ToListAsync();
|
||||
|
||||
var perks = await subscriptions.GetPerkSubscriptionsAsync(
|
||||
accounts.Select(x => x.Id).ToList()
|
||||
);
|
||||
foreach (var account in accounts)
|
||||
if (perks.TryGetValue(account.Id, out var perk))
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
var response = new GetAccountBatchResponse();
|
||||
response.Accounts.AddRange(accounts.Select(a => a.ToProtoValue()));
|
||||
return response;
|
||||
@@ -105,13 +90,6 @@ public class AccountServiceGrpc(
|
||||
.Include(a => a.Profile)
|
||||
.ToListAsync();
|
||||
|
||||
var perks = await subscriptions.GetPerkSubscriptionsAsync(
|
||||
accounts.Select(x => x.Id).ToList()
|
||||
);
|
||||
foreach (var account in accounts)
|
||||
if (perks.TryGetValue(account.Id, out var perk))
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
var response = new GetAccountBatchResponse();
|
||||
response.Accounts.AddRange(accounts.Select(a => a.ToProtoValue()));
|
||||
return response;
|
||||
@@ -148,13 +126,6 @@ public class AccountServiceGrpc(
|
||||
.Include(a => a.Profile)
|
||||
.ToListAsync();
|
||||
|
||||
var perks = await subscriptions.GetPerkSubscriptionsAsync(
|
||||
accounts.Select(x => x.Id).ToList()
|
||||
);
|
||||
foreach (var account in accounts)
|
||||
if (perks.TryGetValue(account.Id, out var perk))
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
var response = new GetAccountBatchResponse();
|
||||
response.Accounts.AddRange(accounts.Select(a => a.ToProtoValue()));
|
||||
return response;
|
||||
@@ -169,13 +140,6 @@ public class AccountServiceGrpc(
|
||||
.Include(a => a.Profile)
|
||||
.ToListAsync();
|
||||
|
||||
var perks = await subscriptions.GetPerkSubscriptionsAsync(
|
||||
accounts.Select(x => x.Id).ToList()
|
||||
);
|
||||
foreach (var account in accounts)
|
||||
if (perks.TryGetValue(account.Id, out var perk))
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
var response = new GetAccountBatchResponse();
|
||||
response.Accounts.AddRange(accounts.Select(a => a.ToProtoValue()));
|
||||
return response;
|
||||
@@ -212,13 +176,6 @@ public class AccountServiceGrpc(
|
||||
.Include(a => a.Profile)
|
||||
.ToListAsync();
|
||||
|
||||
var perks = await subscriptions.GetPerkSubscriptionsAsync(
|
||||
accounts.Select(x => x.Id).ToList()
|
||||
);
|
||||
foreach (var account in accounts)
|
||||
if (perks.TryGetValue(account.Id, out var perk))
|
||||
account.PerkSubscription = perk?.ToReference();
|
||||
|
||||
var response = new ListAccountsResponse
|
||||
{
|
||||
TotalSize = totalCount,
|
||||
@@ -247,7 +204,6 @@ public class AccountServiceGrpc(
|
||||
var relatedRelationship = await relationships.ListAccountFriends(relatedId, true);
|
||||
resp.AccountsId.AddRange(relatedRelationship.Select(x => x.ToString()));
|
||||
return resp;
|
||||
break;
|
||||
case ListRelationshipSimpleRequest.RelationIdentifierOneofCase.None:
|
||||
default:
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument,
|
||||
|
||||
Reference in New Issue
Block a user