person controller and service created

This commit is contained in:
2024-10-02 16:09:11 +02:00
Unverified
parent 3cd282a2e9
commit 9a9e29ecf4
22 changed files with 387 additions and 20 deletions

View File

@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Persons;
public class Person
{
#region PROPERTIES
[JsonPropertyName("name")]
public required string Name { get; set; }
[JsonPropertyName("full_name")]
public string? FullName { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
[JsonPropertyName("birth_date")]
public DateOnly? BirthDate { get; set; }
[JsonPropertyName("death_date")]
public DateOnly? DeathDate { get; set; }
#endregion
}

View File

@@ -0,0 +1,84 @@
using Microsoft.AspNetCore.Mvc;
using WatchIt.Common.Query;
namespace WatchIt.Common.Model.Persons;
public class PersonQueryParameters : QueryParameters<PersonResponse>
{
#region PROPERTIES
[FromQuery(Name = "name")]
public string? Name { get; set; }
[FromQuery(Name = "full_name")]
public string? FullName { get; set; }
[FromQuery(Name = "description")]
public string? Description { get; set; }
[FromQuery(Name = "birth_date")]
public DateOnly? BirthDate { get; set; }
[FromQuery(Name = "birth_date_from")]
public DateOnly? BirthDateFrom { get; set; }
[FromQuery(Name = "birth_date_to")]
public DateOnly? BirthDateTo { get; set; }
[FromQuery(Name = "death_date")]
public DateOnly? DeathDate { get; set; }
[FromQuery(Name = "death_date_from")]
public DateOnly? DeathDateFrom { get; set; }
[FromQuery(Name = "death_date_to")]
public DateOnly? DeathDateTo { get; set; }
[FromQuery(Name = "gender_id")]
public short? GenderId { get; set; }
[FromQuery(Name = "rating_average")]
public decimal? RatingAverage { get; set; }
[FromQuery(Name = "rating_average_from")]
public decimal? RatingAverageFrom { get; set; }
[FromQuery(Name = "rating_average_to")]
public decimal? RatingAverageTo { get; set; }
[FromQuery(Name = "rating_count")]
public long? RatingCount { get; set; }
[FromQuery(Name = "rating_count_from")]
public long? RatingCountFrom { get; set; }
[FromQuery(Name = "rating_count_to")]
public long? RatingCountTo { get; set; }
#endregion
#region PUBLIC METHODS
protected override bool IsMeetingConditions(PersonResponse item) =>
(
TestStringWithRegex(item.Name, Name)
&&
TestStringWithRegex(item.FullName, FullName)
&&
TestStringWithRegex(item.Description, Description)
&&
TestComparable(item.BirthDate, BirthDate, BirthDateFrom, BirthDateTo)
&&
TestComparable(item.DeathDate, DeathDate, DeathDateFrom, DeathDateTo)
&&
Test(item.Gender?.Id, GenderId)
&&
TestComparable(item.Rating.Average, RatingAverage, RatingAverageFrom, RatingAverageTo)
&&
TestComparable(item.Rating.Count, RatingCount, RatingCountFrom, RatingCountTo)
);
#endregion
}

View File

@@ -0,0 +1,29 @@
using System.Text.Json.Serialization;
namespace WatchIt.Common.Model.Persons;
public class PersonRequest : Person
{
#region PROPERTIES
[JsonPropertyName("gender_id")]
public short? GenderId { get; set; }
#endregion
#region PUBLIC METHODS
public Database.Model.Person.Person CreatePerson() => new Database.Model.Person.Person
{
Name = Name,
FullName = FullName,
Description = Description,
BirthDate = BirthDate,
DeathDate = DeathDate,
GenderId = GenderId,
};
#endregion
}

View File

@@ -0,0 +1,57 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using WatchIt.Common.Model.Genders;
using WatchIt.Common.Model.Rating;
using WatchIt.Common.Query;
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
[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;
Rating = RatingResponse.Create(person.PersonActorRoles, person.PersonCreatorRoles);
}
#endregion
}