|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
using System.Globalization; |
|
|
|
using ErsatzTV.Application.MediaItems; |
|
|
|
using ErsatzTV.Application.MediaItems; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Infrastructure.Data; |
|
|
|
using ErsatzTV.Infrastructure.Data; |
|
|
|
@ -25,21 +26,25 @@ public class SearchTelevisionSeasonsHandler : IRequestHandler<SearchTelevisionSe |
|
|
|
where EF.Functions.Like(showMetadata.Title + " " + seasonMetadata.Title, $"%{request.Query}%") |
|
|
|
where EF.Functions.Like(showMetadata.Title + " " + seasonMetadata.Title, $"%{request.Query}%") |
|
|
|
orderby EF.Functions.Collate(showMetadata.Title, TvContext.CaseInsensitiveCollation), season |
|
|
|
orderby EF.Functions.Collate(showMetadata.Title, TvContext.CaseInsensitiveCollation), season |
|
|
|
.SeasonNumber |
|
|
|
.SeasonNumber |
|
|
|
select new TelevisionSeason(season.Id, showMetadata.Title, season.SeasonNumber)) |
|
|
|
select new TelevisionSeason(season.Id, showMetadata.Title, showMetadata.Year, season.SeasonNumber)) |
|
|
|
.Take(20) |
|
|
|
.Take(20) |
|
|
|
.ToListAsync(cancellationToken) |
|
|
|
.ToListAsync(cancellationToken) |
|
|
|
.Map(list => list.Map(ToNamedMediaItem).ToList()); |
|
|
|
.Map(list => list.Map(ToNamedMediaItem).ToList()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static NamedMediaItemViewModel ToNamedMediaItem(TelevisionSeason season) => new( |
|
|
|
private static NamedMediaItemViewModel ToNamedMediaItem(TelevisionSeason season) => |
|
|
|
season.Id, |
|
|
|
new(season.Id, $"{ShowTitle(season)} - {SeasonTitle(season)}"); |
|
|
|
$"{ShowTitle(season)} ({SeasonTitle(season)})"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static string ShowTitle(TelevisionSeason season) => $"{season.Title ?? "???"}"; |
|
|
|
private static string ShowTitle(TelevisionSeason season) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string title = season.Title ?? "???"; |
|
|
|
|
|
|
|
string year = season.Year.HasValue ? season.Year.Value.ToString(CultureInfo.InvariantCulture) : "???"; |
|
|
|
|
|
|
|
return $"{title} ({year})"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static string SeasonTitle(TelevisionSeason season) => season.SeasonNumber == 0 |
|
|
|
private static string SeasonTitle(TelevisionSeason season) => season.SeasonNumber == 0 |
|
|
|
? "Specials" |
|
|
|
? "Specials" |
|
|
|
: $"Season {season.SeasonNumber}"; |
|
|
|
: $"Season {season.SeasonNumber}"; |
|
|
|
|
|
|
|
|
|
|
|
public record TelevisionSeason(int Id, string Title, int SeasonNumber); |
|
|
|
public record TelevisionSeason(int Id, string Title, int? Year, int SeasonNumber); |
|
|
|
} |
|
|
|
} |
|
|
|
|