✨ Payment grpc services and perks in proto
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user