:drunk: No idea what did AI did
This commit is contained in:
80
DysonNetwork.Pass/Features/Auth/Models/Account.cs
Normal file
80
DysonNetwork.Pass/Features/Auth/Models/Account.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using DysonNetwork.Common.Models;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Pass.Features.Auth.Models;
|
||||
|
||||
[Index(nameof(Email), IsUnique = true)]
|
||||
public class Account : ModelBase
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(32)]
|
||||
public string? Status { get; set; }
|
||||
|
||||
[Required]
|
||||
public Instant CreatedAt { get; set; } = SystemClock.Instance.GetCurrentInstant();
|
||||
|
||||
[Required]
|
||||
public Instant UpdatedAt { get; set; } = SystemClock.Instance.GetCurrentInstant();
|
||||
|
||||
// Navigation properties
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<AuthSession> Sessions { get; set; } = new List<AuthSession>();
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<AuthChallenge> Challenges { get; set; } = new List<AuthChallenge>();
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<AccountAuthFactor> AuthFactors { get; set; } = new List<AccountAuthFactor>();
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<AccountConnection> Connections { get; set; } = new List<AccountConnection>();
|
||||
|
||||
public void UpdateTimestamp()
|
||||
{
|
||||
UpdatedAt = SystemClock.Instance.GetCurrentInstant();
|
||||
}
|
||||
|
||||
public static Account FromCommonModel(DysonNetwork.Common.Models.Account commonAccount)
|
||||
{
|
||||
return new Account
|
||||
{
|
||||
Id = Guid.Parse(commonAccount.Id),
|
||||
Email = commonAccount.Profile?.Email ?? string.Empty,
|
||||
Name = commonAccount.Name,
|
||||
Status = commonAccount.Status,
|
||||
CreatedAt = commonAccount.CreatedAt,
|
||||
UpdatedAt = commonAccount.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
public DysonNetwork.Common.Models.Account ToCommonModel()
|
||||
{
|
||||
return new DysonNetwork.Common.Models.Account
|
||||
{
|
||||
Id = Id.ToString(),
|
||||
Name = Name,
|
||||
Status = Status,
|
||||
CreatedAt = CreatedAt,
|
||||
UpdatedAt = UpdatedAt,
|
||||
Profile = new DysonNetwork.Common.Models.Profile
|
||||
{
|
||||
Email = Email,
|
||||
DisplayName = Name
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user