🐛 Fix services unimplmented
This commit is contained in:
@@ -117,6 +117,29 @@ public class SnWalletFund : ModelBase
|
|||||||
ExpiredAt = ExpiredAt.ToTimestamp(),
|
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()
|
public static SnWalletFund FromProtoValue(Proto.WalletFund proto) => new()
|
||||||
{
|
{
|
||||||
Id = Guid.Parse(proto.Id),
|
Id = Guid.Parse(proto.Id),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using DysonNetwork.Shared.Proto;
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
using Google.Protobuf.WellKnownTypes;
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
|
||||||
@@ -133,9 +134,9 @@ public class RemotePaymentService(DysonNetwork.Shared.Proto.PaymentService.Payme
|
|||||||
return response;
|
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);
|
var response = await payment.GetWalletFundAsync(request);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class PostActionController(
|
|||||||
PublisherService pub,
|
PublisherService pub,
|
||||||
AccountService.AccountServiceClient accounts,
|
AccountService.AccountServiceClient accounts,
|
||||||
ActionLogService.ActionLogServiceClient als,
|
ActionLogService.ActionLogServiceClient als,
|
||||||
PaymentService.PaymentServiceClient payments,
|
RemotePaymentService remotePayments,
|
||||||
PollsService polls,
|
PollsService polls,
|
||||||
RemoteRealmService rs
|
RemoteRealmService rs
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
@@ -183,10 +183,7 @@ public class PostActionController(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fundResponse = await payments.GetWalletFundAsync(new GetWalletFundRequest
|
var fundResponse = await remotePayments.GetWalletFund(request.FundId.Value.ToString());
|
||||||
{
|
|
||||||
FundId = request.FundId.Value.ToString()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the fund was created by the current user
|
// Check if the fund was created by the current user
|
||||||
if (fundResponse.CreatorAccountId != currentUser.Id)
|
if (fundResponse.CreatorAccountId != currentUser.Id)
|
||||||
@@ -412,24 +409,21 @@ public class PostActionController(
|
|||||||
var orderRemark = string.IsNullOrWhiteSpace(post.Title)
|
var orderRemark = string.IsNullOrWhiteSpace(post.Title)
|
||||||
? "from @" + post.Publisher.Name
|
? "from @" + post.Publisher.Name
|
||||||
: post.Title;
|
: post.Title;
|
||||||
var order = await payments.CreateOrderAsync(
|
var order = await remotePayments.CreateOrder(
|
||||||
new CreateOrderRequest
|
currency: "points",
|
||||||
{
|
amount: request.Amount.ToString(CultureInfo.InvariantCulture),
|
||||||
ProductIdentifier = "posts.award",
|
productIdentifier: "posts.award",
|
||||||
Currency = "points", // NSP - Source Points
|
remarks: $"Award post {orderRemark}",
|
||||||
Remarks = $"Award post {orderRemark}",
|
meta: GrpcTypeHelper.ConvertObjectToByteString(
|
||||||
Amount = request.Amount.ToString(CultureInfo.InvariantCulture),
|
new Dictionary<string, object?>
|
||||||
Meta = GrpcTypeHelper.ConvertObjectToByteString(
|
{
|
||||||
new Dictionary<string, object?>
|
["account_id"] = accountId,
|
||||||
{
|
["post_id"] = post.Id,
|
||||||
["account_id"] = accountId,
|
["amount"] = request.Amount.ToString(CultureInfo.InvariantCulture),
|
||||||
["post_id"] = post.Id,
|
["message"] = request.Message,
|
||||||
["amount"] = request.Amount.ToString(CultureInfo.InvariantCulture),
|
["attitude"] = request.Attitude,
|
||||||
["message"] = request.Message,
|
}
|
||||||
["attitude"] = request.Attitude,
|
).ToByteArray()
|
||||||
}
|
|
||||||
),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Ok(new PostAwardResponse() { OrderId = Guid.Parse(order.Id) });
|
return Ok(new PostAwardResponse() { OrderId = Guid.Parse(order.Id) });
|
||||||
@@ -675,10 +669,7 @@ public class PostActionController(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fundResponse = await payments.GetWalletFundAsync(new GetWalletFundRequest
|
var fundResponse = await remotePayments.GetWalletFund(request.FundId.Value.ToString());
|
||||||
{
|
|
||||||
FundId = request.FundId.Value.ToString()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the fund was created by the current user
|
// Check if the fund was created by the current user
|
||||||
if (fundResponse.CreatorAccountId != currentUser.Id)
|
if (fundResponse.CreatorAccountId != currentUser.Id)
|
||||||
|
|||||||
@@ -743,15 +743,12 @@ public class PaymentService(
|
|||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SnWalletFund> GetWalletFundAsync(Guid fundId)
|
public async Task<SnWalletFund?> GetWalletFundAsync(Guid fundId)
|
||||||
{
|
{
|
||||||
var fund = await db.WalletFunds
|
var fund = await db.WalletFunds
|
||||||
.Include(f => f.Recipients)
|
.Include(f => f.Recipients)
|
||||||
.FirstOrDefaultAsync(f => f.Id == fundId);
|
.FirstOrDefaultAsync(f => f.Id == fundId);
|
||||||
|
|
||||||
if (fund == null)
|
|
||||||
throw new InvalidOperationException("Fund not found");
|
|
||||||
|
|
||||||
return fund;
|
return fund;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,6 @@ public class PaymentServiceGrpc(PaymentService paymentService)
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
var walletFund = await paymentService.GetWalletFundAsync(Guid.Parse(request.FundId));
|
var walletFund = await paymentService.GetWalletFundAsync(Guid.Parse(request.FundId));
|
||||||
return walletFund.ToProtoValue();
|
return walletFund?.ToProtoValueWithRecipients() ?? new WalletFund();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user