🐛 Fix wallet service didn't impl the Subscription Service Grpc
This commit is contained in:
97
DysonNetwork.Wallet/Payment/SubscriptionServiceGrpc.cs
Normal file
97
DysonNetwork.Wallet/Payment/SubscriptionServiceGrpc.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using DysonNetwork.Shared.Models;
|
||||||
|
using DysonNetwork.Shared.Proto;
|
||||||
|
using DysonNetwork.Shared.Registry;
|
||||||
|
using Grpc.Core;
|
||||||
|
|
||||||
|
namespace DysonNetwork.Wallet.Payment;
|
||||||
|
|
||||||
|
public class SubscriptionServiceGrpc(
|
||||||
|
SubscriptionService subscriptionService,
|
||||||
|
IGrpcClientFactory<AccountService.AccountServiceClient> accountsFactory
|
||||||
|
) : Shared.Proto.SubscriptionService.SubscriptionServiceBase
|
||||||
|
{
|
||||||
|
private readonly AccountService.AccountServiceClient _accounts = accountsFactory.CreateClient();
|
||||||
|
|
||||||
|
public override async Task<Subscription> GetSubscription(
|
||||||
|
GetSubscriptionRequest request,
|
||||||
|
ServerCallContext context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var subscription = await subscriptionService.GetSubscriptionAsync(
|
||||||
|
Guid.Parse(request.AccountId),
|
||||||
|
request.Identifier
|
||||||
|
);
|
||||||
|
return subscription?.ToProtoValue()
|
||||||
|
?? throw new RpcException(new Status(StatusCode.NotFound, "Subscription not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Subscription> GetPerkSubscription(
|
||||||
|
GetPerkSubscriptionRequest request,
|
||||||
|
ServerCallContext context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var subscription = await subscriptionService.GetPerkSubscriptionAsync(
|
||||||
|
Guid.Parse(request.AccountId)
|
||||||
|
);
|
||||||
|
return subscription?.ToProtoValue()
|
||||||
|
?? throw new RpcException(new Status(StatusCode.NotFound, "Perk subscription not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<GetPerkSubscriptionsResponse> GetPerkSubscriptions(
|
||||||
|
GetPerkSubscriptionsRequest request,
|
||||||
|
ServerCallContext context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var accountIds = request.AccountIds.Select(Guid.Parse).ToList();
|
||||||
|
var subscriptions = await subscriptionService.GetPerkSubscriptionsAsync(accountIds);
|
||||||
|
|
||||||
|
var response = new GetPerkSubscriptionsResponse();
|
||||||
|
foreach (var subscription in subscriptions.Values)
|
||||||
|
{
|
||||||
|
if (subscription != null)
|
||||||
|
{
|
||||||
|
response.Subscriptions.Add(subscription.ToProtoValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Subscription> CreateSubscription(
|
||||||
|
CreateSubscriptionRequest request,
|
||||||
|
ServerCallContext context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var account = await _accounts.GetAccountAsync(new GetAccountRequest { Id = request.AccountId });
|
||||||
|
|
||||||
|
if (account == null)
|
||||||
|
{
|
||||||
|
throw new RpcException(new Status(StatusCode.NotFound, "Account not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var subscription = await subscriptionService.CreateSubscriptionAsync(
|
||||||
|
account,
|
||||||
|
request.Identifier,
|
||||||
|
request.PaymentMethod,
|
||||||
|
new SnPaymentDetails(),
|
||||||
|
null,
|
||||||
|
request.HasCouponCode ? request.CouponCode : null,
|
||||||
|
request.IsFreeTrial,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return subscription.ToProtoValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Subscription> CancelSubscription(
|
||||||
|
CancelSubscriptionRequest request,
|
||||||
|
ServerCallContext context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var subscription = await subscriptionService.CancelSubscriptionAsync(
|
||||||
|
Guid.Parse(request.AccountId),
|
||||||
|
request.Identifier
|
||||||
|
);
|
||||||
|
return subscription.ToProtoValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ public static class ApplicationConfiguration
|
|||||||
{
|
{
|
||||||
app.MapGrpcService<WalletServiceGrpc>();
|
app.MapGrpcService<WalletServiceGrpc>();
|
||||||
app.MapGrpcService<PaymentServiceGrpc>();
|
app.MapGrpcService<PaymentServiceGrpc>();
|
||||||
|
app.MapGrpcService<SubscriptionServiceGrpc>();
|
||||||
app.MapGrpcReflectionService();
|
app.MapGrpcReflectionService();
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
|||||||
Reference in New Issue
Block a user