Files
WatchIt/WatchIt.Common/WatchIt.Common.Model/Accounts/AccountResponse.cs

64 lines
1.8 KiB
C#
Raw Normal View History

2024-10-26 02:23:33 +02:00
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Common.Model.Genders;
2024-11-06 16:29:24 +01:00
using WatchIt.Common.Query;
2024-10-26 02:23:33 +02:00
namespace WatchIt.Common.Model.Accounts;
2024-11-06 16:29:24 +01:00
public class AccountResponse : Account, IQueryOrderable<AccountResponse>
2024-10-26 02:23:33 +02:00
{
#region PROPERTIES
2024-11-06 16:29:24 +01:00
[JsonIgnore]
public static IDictionary<string, Func<AccountResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<AccountResponse, IComparable>>
{
{ "id", x => x.Id },
{ "username", x => x.Username },
{ "email", x => x.Email },
{ "description", x => x.Description },
{ "gender", x => x.Gender.Name },
{ "last_active", x => x.LastActive },
{ "creation_date", x => x.CreationDate },
{ "is_admin", x => x.IsAdmin }
};
2024-10-26 02:23:33 +02:00
[JsonPropertyName("id")]
public required long Id { get; set; }
[JsonPropertyName("gender")]
public GenderResponse? Gender { get; set; }
2024-10-30 23:28:47 +01:00
[JsonPropertyName("last_active")]
public DateTime LastActive { get; set; }
[JsonPropertyName("creation_date")]
public DateTime CreationDate { get; set; }
[JsonPropertyName("is_admin")]
public bool IsAdmin { get; set; }
2024-10-26 02:23:33 +02:00
#endregion
#region CONSTRUCTORS
2024-10-28 00:35:32 +01:00
[JsonConstructor]
public AccountResponse() {}
2024-10-26 02:23:33 +02:00
[SetsRequiredMembers]
public AccountResponse(Database.Model.Account.Account account)
{
Id = account.Id;
Username = account.Username;
Email = account.Email;
Description = account.Description;
Gender = account.Gender is not null ? new GenderResponse(account.Gender) : null;
2024-10-30 23:28:47 +01:00
LastActive = account.LastActive;
CreationDate = account.CreationDate;
IsAdmin = account.IsAdmin;
2024-10-26 02:23:33 +02:00
}
#endregion
}