Skip to content

Commit

Permalink
Enhance serialization in UserStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
urumo committed Oct 27, 2024
1 parent 19dd243 commit 2bd12d8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Argon.Api/Argon.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<PackageReference Include="Flurl.Http" Version="4.0.2"/>
<PackageReference Include="Flurl.Http.Newtonsoft" Version="0.9.1"/>
<PackageReference Include="MemoryPack" Version="1.21.3"/>
<PackageReference Include="MemoryPack.Generator" Version="1.21.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10"/>
<PackageReference Include="ActualLab.Fusion" Version="9.5.52"/>
<PackageReference Include="ActualLab.Fusion.EntityFramework.Npgsql" Version="9.5.52"/>
Expand Down
43 changes: 37 additions & 6 deletions src/Argon.Api/Grains.Persistence.States/UserStorage.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
namespace Argon.Api.Grains.Persistence.States;

using System.Runtime.Serialization;
using MemoryPack;
using MessagePack;

[GenerateSerializer]
[Serializable]
[MemoryPackable]
[Alias(nameof(UserStorage))]
public sealed partial record UserStorage
{
[Id(0)] public Guid Id { get; set; } = Guid.Empty;
[Id(1)] public string Username { get; set; } = string.Empty;
[Id(2)] public string Password { get; set; } = string.Empty;
[Id(5)] public string AvatarUrl { get; set; } = string.Empty;
[Id(3)] public DateTime CreatedAt { get; } = DateTime.UtcNow;
[Id(4)] public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
[property: DataMember(Order = 0)]
[property: MemoryPackOrder(0)]
[property: Key(0)]
[Id(0)]
public Guid Id { get; set; } = Guid.Empty;

[property: DataMember(Order = 1)]
[property: MemoryPackOrder(1)]
[property: Key(1)]
[Id(1)]
public string Username { get; set; } = string.Empty;

[property: DataMember(Order = 2)]
[property: MemoryPackOrder(2)]
[property: Key(2)]
[Id(2)]
public string Password { get; set; } = string.Empty;

[property: DataMember(Order = 5)]
[property: MemoryPackOrder(5)]
[property: Key(5)]
[Id(5)]
public string AvatarUrl { get; set; } = string.Empty;

[property: DataMember(Order = 3)]
[property: MemoryPackOrder(3)]
[property: Key(3)]
[Id(3)]
public DateTime CreatedAt { get; } = DateTime.UtcNow;

[property: DataMember(Order = 4)]
[property: MemoryPackOrder(4)]
[property: Key(4)]
[Id(4)]
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

public static implicit operator UserStorageDto(UserStorage userStorage)
{
Expand Down

0 comments on commit 2bd12d8

Please sign in to comment.