🐛 Fix services unimplmented
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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<DysonNetwork.Shared.Proto.WalletFund> GetWalletFund(string fundId)
|
||||
public async Task<WalletFund> 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;
|
||||
}
|
||||
|
||||
@@ -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<string, object?>
|
||||
{
|
||||
["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<string, object?>
|
||||
{
|
||||
["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)
|
||||
|
||||
@@ -743,15 +743,12 @@ public class PaymentService(
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<SnWalletFund> GetWalletFundAsync(Guid fundId)
|
||||
public async Task<SnWalletFund?> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user