Files
WatchIt/WatchIt.Common/WatchIt.Common.Model/Persons/PersonResponse.cs

64 lines
2.0 KiB
C#
Raw Normal View History

2024-10-02 16:09:11 +02:00
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Common.Model.Genders;
using WatchIt.Common.Model.Rating;
using WatchIt.Common.Query;
2024-11-01 20:44:01 +01:00
using WatchIt.Database.Model.Rating;
2024-10-02 16:09:11 +02:00
namespace WatchIt.Common.Model.Persons;
public class PersonResponse : Person, IQueryOrderable<PersonResponse>
{
#region PROPERTIES
[JsonIgnore]
public static IDictionary<string, Func<PersonResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<PersonResponse, IComparable>>
{
{ "id", x => x.Id },
{ "name", x => x.Name },
{ "full_name", x => x.FullName },
{ "description", x => x.Description },
{ "birth_date", x => x.BirthDate },
{ "death_date", x => x.BirthDate },
{ "gender", x => x.Gender.Name },
{ "rating.average", x => x.Rating.Average },
{ "rating.count", x => x.Rating.Count }
};
[JsonPropertyName("id")]
public required long Id { get; set; }
[JsonPropertyName("gender")]
public GenderResponse? Gender { get; set; }
[JsonPropertyName("rating")]
public required RatingResponse Rating { get; set; }
#endregion
#region CONSTRUCTORS
2024-10-05 12:24:38 +02:00
[JsonConstructor]
public PersonResponse() { }
2024-10-02 16:09:11 +02:00
[SetsRequiredMembers]
public PersonResponse(Database.Model.Person.Person person)
{
Id = person.Id;
Name = person.Name;
FullName = person.FullName;
Description = person.Description;
BirthDate = person.BirthDate;
DeathDate = person.DeathDate;
Gender = person.Gender is not null ? new GenderResponse(person.Gender) : null;
2024-11-01 20:44:01 +01:00
Rating = RatingResponseBuilder.Initialize()
.Add(person.PersonActorRoles.SelectMany(x => x.RatingPersonActorRole), x => x.Rating)
.Add(person.PersonCreatorRoles.SelectMany(x => x.RatingPersonCreatorRole), x => x.Rating)
.Build();
2024-10-02 16:09:11 +02:00
}
#endregion
}