|
|
@ -4,6 +4,7 @@ using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Errors; |
|
|
|
using ErsatzTV.Core.Errors; |
|
|
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
|
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
|
|
using ErsatzTV.Core.Metadata; |
|
|
|
using ErsatzTV.Core.Metadata; |
|
|
|
|
|
|
|
using ErsatzTV.Infrastructure.Extensions; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
|
|
|
|
|
|
@ -173,27 +174,35 @@ public class TelevisionRepository : ITelevisionRepository |
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Season>> GetPagedSeasons(int televisionShowId, int pageNumber, int pageSize) |
|
|
|
public async Task<List<Season>> GetPagedSeasons(int televisionShowId, int pageNumber, int pageSize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var result = new List<Season>(); |
|
|
|
|
|
|
|
|
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
|
|
|
|
|
|
|
|
List<int> showIds = await dbContext.Connection.QueryAsync<int>( |
|
|
|
Option<ShowMetadata> maybeShowMetadata = await dbContext.ShowMetadata |
|
|
|
@"SELECT m1.ShowId
|
|
|
|
.SelectOneAsync(sm => sm.Id, sm => sm.ShowId == televisionShowId); |
|
|
|
FROM ShowMetadata m1 |
|
|
|
|
|
|
|
LEFT OUTER JOIN ShowMetadata m2 ON m2.ShowId = @ShowId |
|
|
|
|
|
|
|
WHERE m1.Title = m2.Title AND m1.Year = m2.Year",
|
|
|
|
|
|
|
|
new { ShowId = televisionShowId }) |
|
|
|
|
|
|
|
.Map(results => results.ToList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await dbContext.Seasons |
|
|
|
foreach (ShowMetadata showMetadata in maybeShowMetadata) |
|
|
|
.AsNoTracking() |
|
|
|
{ |
|
|
|
.Where(s => showIds.Contains(s.ShowId)) |
|
|
|
List<int> showIds = await dbContext.ShowMetadata |
|
|
|
.Include(s => s.SeasonMetadata) |
|
|
|
.Filter(sm => sm.Title == showMetadata.Title && sm.Year == showMetadata.Year) |
|
|
|
.ThenInclude(sm => sm.Artwork) |
|
|
|
.Map(sm => sm.ShowId) |
|
|
|
.Include(s => s.Show) |
|
|
|
.ToListAsync(); |
|
|
|
.ThenInclude(s => s.ShowMetadata) |
|
|
|
|
|
|
|
.OrderBy(s => s.SeasonNumber) |
|
|
|
result.AddRange( |
|
|
|
.Skip((pageNumber - 1) * pageSize) |
|
|
|
await dbContext.Seasons |
|
|
|
.Take(pageSize) |
|
|
|
.AsNoTracking() |
|
|
|
.ToListAsync(); |
|
|
|
.Where(s => showIds.Contains(s.ShowId)) |
|
|
|
|
|
|
|
.Include(s => s.SeasonMetadata) |
|
|
|
|
|
|
|
.ThenInclude(sm => sm.Artwork) |
|
|
|
|
|
|
|
.Include(s => s.Show) |
|
|
|
|
|
|
|
.ThenInclude(s => s.ShowMetadata) |
|
|
|
|
|
|
|
.OrderBy(s => s.SeasonNumber) |
|
|
|
|
|
|
|
.Skip((pageNumber - 1) * pageSize) |
|
|
|
|
|
|
|
.Take(pageSize) |
|
|
|
|
|
|
|
.ToListAsync()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> GetEpisodeCount(int seasonId) |
|
|
|
public async Task<int> GetEpisodeCount(int seasonId) |
|
|
|