new ordering system added
This commit is contained in:
@@ -21,9 +21,9 @@ public class GenreQueryParameters : QueryParameters<GenreResponse>
|
|||||||
|
|
||||||
public override bool IsMeetingConditions(GenreResponse item) =>
|
public override bool IsMeetingConditions(GenreResponse item) =>
|
||||||
(
|
(
|
||||||
TestString(item.Name, Name)
|
TestStringWithRegex(item.Name, Name)
|
||||||
&&
|
&&
|
||||||
TestString(item.Description, Description)
|
TestStringWithRegex(item.Description, Description)
|
||||||
);
|
);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Genres;
|
namespace WatchIt.Common.Model.Genres;
|
||||||
|
|
||||||
public class GenreResponse : Genre
|
public class GenreResponse : Genre, IQueryOrderable<GenreResponse>
|
||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public static IDictionary<string, Func<GenreResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<GenreResponse, IComparable>>
|
||||||
|
{
|
||||||
|
{ "id", x => x.Id },
|
||||||
|
{ "name", x => x.Name },
|
||||||
|
{ "description", x => x.Description }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
|
|
||||||
|
namespace WatchIt.Common.Model.Media;
|
||||||
|
|
||||||
|
public class MediaQueryParameters : QueryParameters<MediaResponse>
|
||||||
|
{
|
||||||
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[FromQuery(Name = "type")]
|
||||||
|
public MediaType? Type { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "title")]
|
||||||
|
public string? Title { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "original_title")]
|
||||||
|
public string? OriginalTitle { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "description")]
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "release_date")]
|
||||||
|
public DateOnly? ReleaseDate { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "release_date_from")]
|
||||||
|
public DateOnly? ReleaseDateFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "release_date_to")]
|
||||||
|
public DateOnly? ReleaseDateTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "length")]
|
||||||
|
public short? Length { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "length_from")]
|
||||||
|
public short? LengthFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "length_to")]
|
||||||
|
public short? LengthTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average")]
|
||||||
|
public double? RatingAverage { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_from")]
|
||||||
|
public double? RatingAverageFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_to")]
|
||||||
|
public double? RatingAverageTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count")]
|
||||||
|
public double? RatingCount { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_from")]
|
||||||
|
public double? RatingCountFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_to")]
|
||||||
|
public double? RatingCountTo { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region PUBLIC METHODS
|
||||||
|
|
||||||
|
public override bool IsMeetingConditions(MediaResponse item) =>
|
||||||
|
(
|
||||||
|
Test(item.Type, Type)
|
||||||
|
&&
|
||||||
|
TestStringWithRegex(item.Title, Title)
|
||||||
|
&&
|
||||||
|
TestStringWithRegex(item.OriginalTitle, OriginalTitle)
|
||||||
|
&&
|
||||||
|
TestStringWithRegex(item.Description, Description)
|
||||||
|
&&
|
||||||
|
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Length, Length, LengthFrom, LengthTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Average, RatingAverage, RatingAverageFrom, RatingAverageTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Count, RatingCount, RatingCountFrom, RatingCountTo)
|
||||||
|
);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,18 +1,37 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Common.Model.Rating;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Media;
|
namespace WatchIt.Common.Model.Media;
|
||||||
|
|
||||||
public class MediaResponse : Media
|
public class MediaResponse : Media, IQueryOrderable<MediaResponse>
|
||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public static IDictionary<string, Func<MediaResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<MediaResponse, IComparable>>
|
||||||
|
{
|
||||||
|
{ "id", x => x.Id },
|
||||||
|
{ "title", x => x.Title },
|
||||||
|
{ "original_title", x => x.OriginalTitle },
|
||||||
|
{ "description", x => x.Description },
|
||||||
|
{ "release_date", x => x.ReleaseDate },
|
||||||
|
{ "length", x => x.Length },
|
||||||
|
{ "rating.average", x => x.Rating.Average },
|
||||||
|
{ "rating.count", x => x.Rating.Count }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("type")]
|
[JsonPropertyName("type")]
|
||||||
public MediaType Type { get; set; }
|
public MediaType Type { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("rating")]
|
||||||
|
public RatingResponse Rating { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +51,7 @@ public class MediaResponse : Media
|
|||||||
ReleaseDate = media.ReleaseDate;
|
ReleaseDate = media.ReleaseDate;
|
||||||
Length = media.Length;
|
Length = media.Length;
|
||||||
Type = mediaType;
|
Type = mediaType;
|
||||||
|
Rating = new RatingResponse(media.RatingMedia);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -43,6 +43,24 @@ public class MovieQueryParameters : QueryParameters<MovieResponse>
|
|||||||
[FromQuery(Name = "budget_to")]
|
[FromQuery(Name = "budget_to")]
|
||||||
public decimal? BudgetTo { get; set; }
|
public decimal? BudgetTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average")]
|
||||||
|
public double? RatingAverage { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_from")]
|
||||||
|
public double? RatingAverageFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_to")]
|
||||||
|
public double? RatingAverageTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count")]
|
||||||
|
public double? RatingCount { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_from")]
|
||||||
|
public double? RatingCountFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_to")]
|
||||||
|
public double? RatingCountTo { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -51,17 +69,21 @@ public class MovieQueryParameters : QueryParameters<MovieResponse>
|
|||||||
|
|
||||||
public override bool IsMeetingConditions(MovieResponse item) =>
|
public override bool IsMeetingConditions(MovieResponse item) =>
|
||||||
(
|
(
|
||||||
TestString(item.Title, Title)
|
TestStringWithRegex(item.Title, Title)
|
||||||
&&
|
&&
|
||||||
TestString(item.OriginalTitle, OriginalTitle)
|
TestStringWithRegex(item.OriginalTitle, OriginalTitle)
|
||||||
&&
|
&&
|
||||||
TestString(item.Description, Description)
|
TestStringWithRegex(item.Description, Description)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
|
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.Length, Length, LengthFrom, LengthTo)
|
TestComparable(item.Length, Length, LengthFrom, LengthTo)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.Budget, Budget, BudgetFrom, BudgetTo)
|
TestComparable(item.Budget, Budget, BudgetFrom, BudgetTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Average, RatingAverage, RatingAverageFrom, RatingAverageTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Count, RatingCount, RatingCountFrom, RatingCountTo)
|
||||||
);
|
);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,16 +1,36 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Common.Model.Rating;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
using WatchIt.Database.Model.Media;
|
using WatchIt.Database.Model.Media;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Movies;
|
namespace WatchIt.Common.Model.Movies;
|
||||||
|
|
||||||
public class MovieResponse : Movie
|
public class MovieResponse : Movie, IQueryOrderable<MovieResponse>
|
||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public static IDictionary<string, Func<MovieResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<MovieResponse, IComparable>>
|
||||||
|
{
|
||||||
|
{ "id", x => x.Id },
|
||||||
|
{ "title", x => x.Title },
|
||||||
|
{ "original_title", x => x.OriginalTitle },
|
||||||
|
{ "description", x => x.Description },
|
||||||
|
{ "release_date", x => x.ReleaseDate },
|
||||||
|
{ "length", x => x.Length },
|
||||||
|
{ "budget", x => x.Budget },
|
||||||
|
{ "rating.average", x => x.Rating.Average },
|
||||||
|
{ "rating.count", x => x.Rating.Count }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("rating")]
|
||||||
|
public RatingResponse Rating { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -30,6 +50,7 @@ public class MovieResponse : Movie
|
|||||||
ReleaseDate = mediaMovie.Media.ReleaseDate;
|
ReleaseDate = mediaMovie.Media.ReleaseDate;
|
||||||
Length = mediaMovie.Media.Length;
|
Length = mediaMovie.Media.Length;
|
||||||
Budget = mediaMovie.Budget;
|
Budget = mediaMovie.Budget;
|
||||||
|
Rating = new RatingResponse(mediaMovie.Media.RatingMedia);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using WatchIt.Common.Model.Media;
|
using WatchIt.Common.Model.Media;
|
||||||
|
using WatchIt.Common.Model.Series;
|
||||||
using WatchIt.Common.Query;
|
using WatchIt.Common.Query;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Photos;
|
namespace WatchIt.Common.Model.Photos;
|
||||||
@@ -34,11 +36,11 @@ public class PhotoQueryParameters : QueryParameters<PhotoResponse>
|
|||||||
|
|
||||||
public override bool IsMeetingConditions(PhotoResponse item) =>
|
public override bool IsMeetingConditions(PhotoResponse item) =>
|
||||||
(
|
(
|
||||||
TestString(item.MimeType, MimeType)
|
TestStringWithRegex(item.MimeType, MimeType)
|
||||||
&&
|
&&
|
||||||
TestBoolean(item.Background is not null, IsBackground)
|
Test(item.Background is not null, IsBackground)
|
||||||
&&
|
&&
|
||||||
TestBoolean(item.Background is not null && item.Background.IsUniversalBackground, IsUniversalBackground)
|
Test(item.Background is not null && item.Background.IsUniversalBackground, IsUniversalBackground)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.UploadDate, UploadDate, UploadDateFrom, UploadDateTo)
|
TestComparable(item.UploadDate, UploadDate, UploadDateFrom, UploadDateTo)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,25 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
using WatchIt.Database.Model.Media;
|
using WatchIt.Database.Model.Media;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Photos;
|
namespace WatchIt.Common.Model.Photos;
|
||||||
|
|
||||||
public class PhotoResponse : Photo
|
public class PhotoResponse : Photo, IQueryOrderable<PhotoResponse>
|
||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public static IDictionary<string, Func<PhotoResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<PhotoResponse, IComparable>>
|
||||||
|
{
|
||||||
|
{ "id", x => x.Id },
|
||||||
|
{ "media_id", x => x.MediaId },
|
||||||
|
{ "mime_type", x => x.MimeType },
|
||||||
|
{ "is_background", x => x.Background is not null },
|
||||||
|
{ "is_universal_background", x => x.Background is not null && x.Background.IsUniversalBackground }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Database.Model.Rating;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Rating;
|
namespace WatchIt.Common.Model.Rating;
|
||||||
|
|
||||||
@@ -7,11 +8,11 @@ public class RatingResponse
|
|||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
[JsonPropertyName("rating_average")]
|
[JsonPropertyName("average")]
|
||||||
public required double RatingAverage { get; set; }
|
public required double Average { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("rating_count")]
|
[JsonPropertyName("count")]
|
||||||
public required long RatingCount { get; set; }
|
public required long Count { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -22,11 +23,14 @@ public class RatingResponse
|
|||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public RatingResponse() {}
|
public RatingResponse() {}
|
||||||
|
|
||||||
|
[SetsRequiredMembers]
|
||||||
|
public RatingResponse(IEnumerable<RatingMedia> ratingMedia) : this(ratingMedia.Any() ? ratingMedia.Average(x => x.Rating) : 0, ratingMedia.Count()) {}
|
||||||
|
|
||||||
[SetsRequiredMembers]
|
[SetsRequiredMembers]
|
||||||
public RatingResponse(double ratingAverage, long ratingCount)
|
public RatingResponse(double ratingAverage, long ratingCount)
|
||||||
{
|
{
|
||||||
RatingAverage = ratingAverage;
|
Average = ratingAverage;
|
||||||
RatingCount = ratingCount;
|
Count = ratingCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -37,6 +37,24 @@ public class SeriesQueryParameters : QueryParameters<SeriesResponse>
|
|||||||
[FromQuery(Name = "has_ended")]
|
[FromQuery(Name = "has_ended")]
|
||||||
public bool? HasEnded { get; set; }
|
public bool? HasEnded { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average")]
|
||||||
|
public double? RatingAverage { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_from")]
|
||||||
|
public double? RatingAverageFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_average_to")]
|
||||||
|
public double? RatingAverageTo { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count")]
|
||||||
|
public double? RatingCount { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_from")]
|
||||||
|
public double? RatingCountFrom { get; set; }
|
||||||
|
|
||||||
|
[FromQuery(Name = "rating_count_to")]
|
||||||
|
public double? RatingCountTo { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -45,17 +63,21 @@ public class SeriesQueryParameters : QueryParameters<SeriesResponse>
|
|||||||
|
|
||||||
public override bool IsMeetingConditions(SeriesResponse item) =>
|
public override bool IsMeetingConditions(SeriesResponse item) =>
|
||||||
(
|
(
|
||||||
TestString(item.Title, Title)
|
TestStringWithRegex(item.Title, Title)
|
||||||
&&
|
&&
|
||||||
TestString(item.OriginalTitle, OriginalTitle)
|
TestStringWithRegex(item.OriginalTitle, OriginalTitle)
|
||||||
&&
|
&&
|
||||||
TestString(item.Description, Description)
|
TestStringWithRegex(item.Description, Description)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
|
TestComparable(item.ReleaseDate, ReleaseDate, ReleaseDateFrom, ReleaseDateTo)
|
||||||
&&
|
&&
|
||||||
TestComparable(item.Length, Length, LengthFrom, LengthTo)
|
TestComparable(item.Length, Length, LengthFrom, LengthTo)
|
||||||
&&
|
&&
|
||||||
TestBoolean(item.HasEnded, HasEnded)
|
Test(item.HasEnded, HasEnded)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Average, RatingAverage, RatingAverageFrom, RatingAverageTo)
|
||||||
|
&&
|
||||||
|
TestComparable(item.Rating.Count, RatingCount, RatingCountFrom, RatingCountTo)
|
||||||
);
|
);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,16 +1,36 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using WatchIt.Common.Model.Rating;
|
||||||
|
using WatchIt.Common.Query;
|
||||||
using WatchIt.Database.Model.Media;
|
using WatchIt.Database.Model.Media;
|
||||||
|
|
||||||
namespace WatchIt.Common.Model.Series;
|
namespace WatchIt.Common.Model.Series;
|
||||||
|
|
||||||
public class SeriesResponse : Series
|
public class SeriesResponse : Series, IQueryOrderable<SeriesResponse>
|
||||||
{
|
{
|
||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public static IDictionary<string, Func<SeriesResponse, IComparable>> OrderableProperties { get; } = new Dictionary<string, Func<SeriesResponse, IComparable>>
|
||||||
|
{
|
||||||
|
{ "id", x => x.Id },
|
||||||
|
{ "title", x => x.Title },
|
||||||
|
{ "original_title", x => x.OriginalTitle },
|
||||||
|
{ "description", x => x.Description },
|
||||||
|
{ "release_date", x => x.ReleaseDate },
|
||||||
|
{ "length", x => x.Length },
|
||||||
|
{ "has_ended", x => x.HasEnded },
|
||||||
|
{ "rating.average", x => x.Rating.Average },
|
||||||
|
{ "rating.count", x => x.Rating.Count }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("rating")]
|
||||||
|
public RatingResponse Rating { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -30,6 +50,7 @@ public class SeriesResponse : Series
|
|||||||
ReleaseDate = mediaSeries.Media.ReleaseDate;
|
ReleaseDate = mediaSeries.Media.ReleaseDate;
|
||||||
Length = mediaSeries.Media.Length;
|
Length = mediaSeries.Media.Length;
|
||||||
HasEnded = mediaSeries.HasEnded;
|
HasEnded = mediaSeries.HasEnded;
|
||||||
|
Rating = new RatingResponse(mediaSeries.Media.RatingMedia);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
9
WatchIt.Common/WatchIt.Common.Query/IQueryOrderable.cs
Normal file
9
WatchIt.Common/WatchIt.Common.Query/IQueryOrderable.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace WatchIt.Common.Query;
|
||||||
|
|
||||||
|
public interface IQueryOrderable<T>
|
||||||
|
{
|
||||||
|
[JsonIgnore]
|
||||||
|
public static abstract IDictionary<string, Func<T, IComparable>> OrderableProperties { get; }
|
||||||
|
}
|
||||||
@@ -52,14 +52,18 @@ public abstract class QueryParameters
|
|||||||
|
|
||||||
#region PRIVATE METHODS
|
#region PRIVATE METHODS
|
||||||
|
|
||||||
protected static bool TestBoolean(bool property, bool? query) =>
|
protected static bool Test<T>(T? property, T? query) =>
|
||||||
(
|
(
|
||||||
query is null
|
query is null
|
||||||
||
|
||
|
||||||
property == query
|
(
|
||||||
|
property is not null
|
||||||
|
&&
|
||||||
|
property.Equals(query)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
protected static bool TestString(string? property, string? regexQuery) =>
|
protected static bool TestStringWithRegex(string? property, string? regexQuery) =>
|
||||||
(
|
(
|
||||||
string.IsNullOrEmpty(regexQuery)
|
string.IsNullOrEmpty(regexQuery)
|
||||||
||
|
||
|
||||||
@@ -108,7 +112,7 @@ public abstract class QueryParameters
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class QueryParameters<T> : QueryParameters where T : class
|
public abstract class QueryParameters<T> : QueryParameters where T : IQueryOrderable<T>
|
||||||
{
|
{
|
||||||
#region PUBLIC METHODS
|
#region PUBLIC METHODS
|
||||||
|
|
||||||
@@ -120,22 +124,9 @@ public abstract class QueryParameters<T> : QueryParameters where T : class
|
|||||||
|
|
||||||
if (OrderBy is not null)
|
if (OrderBy is not null)
|
||||||
{
|
{
|
||||||
PropertyInfo[] properties = typeof(T).GetProperties();
|
if (T.OrderableProperties.TryGetValue(OrderBy, out Func<T, IComparable>? orderFunc))
|
||||||
foreach (PropertyInfo property in properties)
|
|
||||||
{
|
{
|
||||||
JsonPropertyNameAttribute? attribute = property.GetCustomAttributes<JsonPropertyNameAttribute>(true).FirstOrDefault();
|
data = Order == "asc" ? data.OrderBy(orderFunc) : data.OrderByDescending(orderFunc);
|
||||||
if (attribute is not null && attribute.Name == OrderBy)
|
|
||||||
{
|
|
||||||
if (Order == "asc")
|
|
||||||
{
|
|
||||||
data = data.OrderBy(property.GetValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data = data.OrderByDescending(property.GetValue);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (After is not null)
|
if (After is not null)
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
<div class="d-inline-flex gap-2">
|
<div class="d-inline-flex gap-2">
|
||||||
<span id="ratingStar">★</span>
|
<span id="ratingStar">★</span>
|
||||||
<div class="d-inline-flex flex-column justify-content-center">
|
<div class="d-inline-flex flex-column justify-content-center">
|
||||||
<span id="ratingValue">@(_rating is not null && _rating.RatingCount > 0 ? _rating.RatingAverage : "--")/10</span>
|
<span id="ratingValue">@(Rating.Count > 0 ? Rating.Average : "--")/10</span>
|
||||||
@if (_rating is not null && _rating.RatingCount > 0)
|
@if (Rating.Count > 0)
|
||||||
{
|
{
|
||||||
<span id="ratingCount">@(_rating.RatingCount)</span>
|
<span id="ratingCount">@(Rating.Count)</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ public partial class ListItemComponent : ComponentBase
|
|||||||
[Parameter] public required long Id { get; set; }
|
[Parameter] public required long Id { get; set; }
|
||||||
[Parameter] public required string Name { get; set; }
|
[Parameter] public required string Name { get; set; }
|
||||||
[Parameter] public string? AdditionalNameInfo { get; set; }
|
[Parameter] public string? AdditionalNameInfo { get; set; }
|
||||||
|
[Parameter] public required RatingResponse Rating { get; set; }
|
||||||
[Parameter] public required Func<long, Action<Picture>, Task> PictureDownloadingTask { get; set; }
|
[Parameter] public required Func<long, Action<Picture>, Task> PictureDownloadingTask { get; set; }
|
||||||
[Parameter] public required Func<long, Action<RatingResponse>, Task> RatingDownloadingTask { get; set; }
|
|
||||||
[Parameter] public int PictureHeight { get; set; } = 150;
|
[Parameter] public int PictureHeight { get; set; } = 150;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -24,7 +24,6 @@ public partial class ListItemComponent : ComponentBase
|
|||||||
private bool _loaded;
|
private bool _loaded;
|
||||||
|
|
||||||
private Picture? _picture;
|
private Picture? _picture;
|
||||||
private RatingResponse? _rating;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -42,7 +41,6 @@ public partial class ListItemComponent : ComponentBase
|
|||||||
endTasks.AddRange(
|
endTasks.AddRange(
|
||||||
[
|
[
|
||||||
PictureDownloadingTask(Id, picture => _picture = picture),
|
PictureDownloadingTask(Id, picture => _picture = picture),
|
||||||
RatingDownloadingTask(Id, rating => _rating = rating)
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await Task.WhenAll(endTasks);
|
await Task.WhenAll(endTasks);
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
<ListItemComponent Id="@(IdSource(_items[i]))"
|
<ListItemComponent Id="@(IdSource(_items[i]))"
|
||||||
Name="@(NameSource(_items[i]))"
|
Name="@(NameSource(_items[i]))"
|
||||||
AdditionalNameInfo="@(AdditionalNameInfoSource(_items[i]))"
|
AdditionalNameInfo="@(AdditionalNameInfoSource(_items[i]))"
|
||||||
PictureDownloadingTask="@(PictureDownloadingTask)"
|
Rating="@(RatingSource(_items[i]))"
|
||||||
RatingDownloadingTask="@(RatingDownloadingTask)"/>
|
PictureDownloadingTask="@(PictureDownloadingTask)"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ public partial class SearchResultComponent<TItem, TQuery> : ComponentBase where
|
|||||||
[Parameter] public required Func<TItem, long> IdSource { get; set; }
|
[Parameter] public required Func<TItem, long> IdSource { get; set; }
|
||||||
[Parameter] public required Func<TItem, string> NameSource { get; set; }
|
[Parameter] public required Func<TItem, string> NameSource { get; set; }
|
||||||
[Parameter] public Func<TItem, string?> AdditionalNameInfoSource { get; set; } = _ => null;
|
[Parameter] public Func<TItem, string?> AdditionalNameInfoSource { get; set; } = _ => null;
|
||||||
|
[Parameter] public required Func<TItem, RatingResponse> RatingSource { get; set; }
|
||||||
[Parameter] public required string UrlIdTemplate { get; set; }
|
[Parameter] public required string UrlIdTemplate { get; set; }
|
||||||
[Parameter] public required Func<TQuery, Action<IEnumerable<TItem>>, Task> ItemDownloadingTask { get; set; }
|
[Parameter] public required Func<TQuery, Action<IEnumerable<TItem>>, Task> ItemDownloadingTask { get; set; }
|
||||||
[Parameter] public required Func<long, Action<Picture>, Task> PictureDownloadingTask { get; set; }
|
[Parameter] public required Func<long, Action<Picture>, Task> PictureDownloadingTask { get; set; }
|
||||||
[Parameter] public required Func<long, Action<RatingResponse>, Task> RatingDownloadingTask { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ else
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h4 class="text-dark">
|
<h4 class="text-dark">
|
||||||
<strong>Global rating:</strong> @(_globalRating.RatingCount == 0 ? "no ratings" : $"{Math.Round(_globalRating.RatingAverage, 1)}/10")
|
<strong>Global rating:</strong> @(_globalRating.Count == 0 ? "no ratings" : $"{Math.Round(_globalRating.Average, 1)}/10")
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,10 +37,10 @@
|
|||||||
IdSource="@(item => item.Id)"
|
IdSource="@(item => item.Id)"
|
||||||
NameSource="@(item => item.Title)"
|
NameSource="@(item => item.Title)"
|
||||||
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
|
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
|
||||||
Query="@(new MovieQueryParameters { Title = DecodedQuery })"
|
RatingSource="@(item => item.Rating)"
|
||||||
|
Query="@(new MovieQueryParameters { Title = DecodedQuery, OrderBy = "rating.count" })"
|
||||||
ItemDownloadingTask="@(MoviesWebAPIService.GetAllMovies)"
|
ItemDownloadingTask="@(MoviesWebAPIService.GetAllMovies)"
|
||||||
PictureDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaPoster(id, action))"
|
PictureDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaPoster(id, action))"/>
|
||||||
RatingDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaRating(id, action))"/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
@@ -52,10 +52,10 @@
|
|||||||
IdSource="@(item => item.Id)"
|
IdSource="@(item => item.Id)"
|
||||||
NameSource="@(item => item.Title)"
|
NameSource="@(item => item.Title)"
|
||||||
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
|
AdditionalNameInfoSource="@(item => item.ReleaseDate.HasValue ? $" ({item.ReleaseDate.Value.Year})" : null)"
|
||||||
Query="@(new SeriesQueryParameters { Title = DecodedQuery })"
|
RatingSource="@(item => item.Rating)"
|
||||||
|
Query="@(new SeriesQueryParameters { Title = DecodedQuery, OrderBy = "rating.count" })"
|
||||||
ItemDownloadingTask="@(SeriesWebAPIService.GetAllSeries)"
|
ItemDownloadingTask="@(SeriesWebAPIService.GetAllSeries)"
|
||||||
PictureDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaPoster(id, action))"
|
PictureDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaPoster(id, action))"/>
|
||||||
RatingDownloadingTask="@((id, action) => MediaWebAPIService.GetMediaRating(id, action))"/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user