Payment grpc services and perks in proto

This commit is contained in:
2025-07-23 20:14:02 +08:00
parent 8e61a8b43d
commit 925ddd9e8b
10 changed files with 542 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Text.Json.Serialization;
using DysonNetwork.Shared.Data;
using NodaTime.Serialization.Protobuf;
namespace DysonNetwork.Pass.Wallet;
@@ -12,6 +14,29 @@ public class Wallet : ModelBase
public Guid AccountId { get; set; }
public Account.Account Account { get; set; } = null!;
public Shared.Proto.Wallet ToProtoValue()
{
var proto = new Shared.Proto.Wallet
{
Id = Id.ToString(),
AccountId = AccountId.ToString(),
};
foreach (var pocket in Pockets)
{
proto.Pockets.Add(pocket.ToProtoValue());
}
return proto;
}
public static Wallet FromProtoValue(Shared.Proto.Wallet proto) => new()
{
Id = Guid.Parse(proto.Id),
AccountId = Guid.Parse(proto.AccountId),
Pockets = proto.Pockets.Select(WalletPocket.FromProtoValue).ToList(),
};
}
public class WalletPocket : ModelBase
@@ -22,4 +47,20 @@ public class WalletPocket : ModelBase
public Guid WalletId { get; set; }
[JsonIgnore] public Wallet Wallet { get; set; } = null!;
public Shared.Proto.WalletPocket ToProtoValue() => new()
{
Id = Id.ToString(),
Currency = Currency,
Amount = Amount.ToString(CultureInfo.CurrentCulture),
WalletId = WalletId.ToString(),
};
public static WalletPocket FromProtoValue(Shared.Proto.WalletPocket proto) => new()
{
Id = Guid.Parse(proto.Id),
Currency = proto.Currency,
Amount = decimal.Parse(proto.Amount),
WalletId = Guid.Parse(proto.WalletId),
};
}