From 2641814a229127cfcec4e1c25f442473dee78396 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 4 Feb 2026 13:54:47 +0800 Subject: [PATCH] :bug: Fix services unimplmented --- DysonNetwork.Shared/Models/Wallet.cs | 23 ++++++++++ .../Registry/RemotePaymentService.cs | 5 ++- .../Post/PostActionController.cs | 45 ++++++++----------- DysonNetwork.Wallet/Payment/PaymentService.cs | 5 +-- .../Payment/PaymentServiceGrpc.cs | 2 +- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/DysonNetwork.Shared/Models/Wallet.cs b/DysonNetwork.Shared/Models/Wallet.cs index 48f8483d..48983fc3 100644 --- a/DysonNetwork.Shared/Models/Wallet.cs +++ b/DysonNetwork.Shared/Models/Wallet.cs @@ -117,6 +117,29 @@ public class SnWalletFund : ModelBase ExpiredAt = ExpiredAt.ToTimestamp(), }; + public Proto.WalletFund ToProtoValueWithRecipients() + { + var proto = new Proto.WalletFund + { + Id = Id.ToString(), + Currency = Currency, + TotalAmount = TotalAmount.ToString(CultureInfo.InvariantCulture), + RemainingAmount = RemainingAmount.ToString(CultureInfo.InvariantCulture), + SplitType = (Proto.FundSplitType)SplitType, + Status = (Proto.FundStatus)Status, + Message = Message, + CreatorAccountId = CreatorAccountId.ToString(), + ExpiredAt = ExpiredAt.ToTimestamp(), + }; + + foreach (var recipient in Recipients) + { + proto.Recipients.Add(recipient.ToProtoValue()); + } + + return proto; + } + public static SnWalletFund FromProtoValue(Proto.WalletFund proto) => new() { Id = Guid.Parse(proto.Id), diff --git a/DysonNetwork.Shared/Registry/RemotePaymentService.cs b/DysonNetwork.Shared/Registry/RemotePaymentService.cs index 54151f1e..b646c055 100644 --- a/DysonNetwork.Shared/Registry/RemotePaymentService.cs +++ b/DysonNetwork.Shared/Registry/RemotePaymentService.cs @@ -1,3 +1,4 @@ +using DysonNetwork.Shared.Proto; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; @@ -133,9 +134,9 @@ public class RemotePaymentService(DysonNetwork.Shared.Proto.PaymentService.Payme return response; } - public async Task GetWalletFund(string fundId) + public async Task GetWalletFund(string fundId) { - var request = new DysonNetwork.Shared.Proto.GetWalletFundRequest { FundId = fundId }; + var request = new GetWalletFundRequest { FundId = fundId }; var response = await payment.GetWalletFundAsync(request); return response; } diff --git a/DysonNetwork.Sphere/Post/PostActionController.cs b/DysonNetwork.Sphere/Post/PostActionController.cs index f308cffe..bd3c9891 100644 --- a/DysonNetwork.Sphere/Post/PostActionController.cs +++ b/DysonNetwork.Sphere/Post/PostActionController.cs @@ -30,7 +30,7 @@ public class PostActionController( PublisherService pub, AccountService.AccountServiceClient accounts, ActionLogService.ActionLogServiceClient als, - PaymentService.PaymentServiceClient payments, + RemotePaymentService remotePayments, PollsService polls, RemoteRealmService rs ) : ControllerBase @@ -183,10 +183,7 @@ public class PostActionController( { try { - var fundResponse = await payments.GetWalletFundAsync(new GetWalletFundRequest - { - FundId = request.FundId.Value.ToString() - }); + var fundResponse = await remotePayments.GetWalletFund(request.FundId.Value.ToString()); // Check if the fund was created by the current user if (fundResponse.CreatorAccountId != currentUser.Id) @@ -412,24 +409,21 @@ public class PostActionController( var orderRemark = string.IsNullOrWhiteSpace(post.Title) ? "from @" + post.Publisher.Name : post.Title; - var order = await payments.CreateOrderAsync( - new CreateOrderRequest - { - ProductIdentifier = "posts.award", - Currency = "points", // NSP - Source Points - Remarks = $"Award post {orderRemark}", - Amount = request.Amount.ToString(CultureInfo.InvariantCulture), - Meta = GrpcTypeHelper.ConvertObjectToByteString( - new Dictionary - { - ["account_id"] = accountId, - ["post_id"] = post.Id, - ["amount"] = request.Amount.ToString(CultureInfo.InvariantCulture), - ["message"] = request.Message, - ["attitude"] = request.Attitude, - } - ), - } + var order = await remotePayments.CreateOrder( + currency: "points", + amount: request.Amount.ToString(CultureInfo.InvariantCulture), + productIdentifier: "posts.award", + remarks: $"Award post {orderRemark}", + meta: GrpcTypeHelper.ConvertObjectToByteString( + new Dictionary + { + ["account_id"] = accountId, + ["post_id"] = post.Id, + ["amount"] = request.Amount.ToString(CultureInfo.InvariantCulture), + ["message"] = request.Message, + ["attitude"] = request.Attitude, + } + ).ToByteArray() ); return Ok(new PostAwardResponse() { OrderId = Guid.Parse(order.Id) }); @@ -675,10 +669,7 @@ public class PostActionController( { try { - var fundResponse = await payments.GetWalletFundAsync(new GetWalletFundRequest - { - FundId = request.FundId.Value.ToString() - }); + var fundResponse = await remotePayments.GetWalletFund(request.FundId.Value.ToString()); // Check if the fund was created by the current user if (fundResponse.CreatorAccountId != currentUser.Id) diff --git a/DysonNetwork.Wallet/Payment/PaymentService.cs b/DysonNetwork.Wallet/Payment/PaymentService.cs index ea7dd156..bbd35faa 100644 --- a/DysonNetwork.Wallet/Payment/PaymentService.cs +++ b/DysonNetwork.Wallet/Payment/PaymentService.cs @@ -743,15 +743,12 @@ public class PaymentService( await db.SaveChangesAsync(); } - public async Task GetWalletFundAsync(Guid fundId) + public async Task GetWalletFundAsync(Guid fundId) { var fund = await db.WalletFunds .Include(f => f.Recipients) .FirstOrDefaultAsync(f => f.Id == fundId); - if (fund == null) - throw new InvalidOperationException("Fund not found"); - return fund; } diff --git a/DysonNetwork.Wallet/Payment/PaymentServiceGrpc.cs b/DysonNetwork.Wallet/Payment/PaymentServiceGrpc.cs index 16f8f91d..5f5129a4 100644 --- a/DysonNetwork.Wallet/Payment/PaymentServiceGrpc.cs +++ b/DysonNetwork.Wallet/Payment/PaymentServiceGrpc.cs @@ -107,6 +107,6 @@ public class PaymentServiceGrpc(PaymentService paymentService) ) { var walletFund = await paymentService.GetWalletFundAsync(Guid.Parse(request.FundId)); - return walletFund.ToProtoValue(); + return walletFund?.ToProtoValueWithRecipients() ?? new WalletFund(); } }