mirror of https://github.com/ErsatzTV/ErsatzTV.git
17 changed files with 13445 additions and 22 deletions
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
namespace ErsatzTV.Application.Playouts; |
||||
|
||||
public record PagedPlayoutsViewModel(int TotalCount, List<PlayoutNameViewModel> Page); |
||||
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
namespace ErsatzTV.Application.Playouts; |
||||
|
||||
public record GetPagedPlayouts(string Query, int PageNum, int PageSize) : IRequest<PagedPlayoutsViewModel>; |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Infrastructure.Data; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using static ErsatzTV.Application.Playouts.Mapper; |
||||
|
||||
namespace ErsatzTV.Application.Playouts; |
||||
|
||||
public class GetPagedPlayoutsHandler(IDbContextFactory<TvContext> dbContextFactory) |
||||
: IRequestHandler<GetPagedPlayouts, PagedPlayoutsViewModel> |
||||
{ |
||||
public async Task<PagedPlayoutsViewModel> Handle( |
||||
GetPagedPlayouts request, |
||||
CancellationToken cancellationToken) |
||||
{ |
||||
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
||||
int count = await dbContext.Playouts.CountAsync(cancellationToken); |
||||
|
||||
IQueryable<Playout> query = dbContext.Playouts |
||||
.AsNoTracking() |
||||
.Include(p => p.Channel) |
||||
.Include(p => p.ProgramSchedule) |
||||
.Filter(p => p.Channel != null); |
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Query)) |
||||
{ |
||||
query = query.Where(p => EF.Functions.Like( |
||||
EF.Functions.Collate(p.Channel.Name, TvContext.CaseInsensitiveCollation), |
||||
$"%{request.Query}%")); |
||||
} |
||||
|
||||
List<PlayoutNameViewModel> page = await query |
||||
.OrderBy(p => p.Channel.SortNumber) |
||||
.Skip(request.PageNum * request.PageSize) |
||||
.Take(request.PageSize) |
||||
.ToListAsync(cancellationToken) |
||||
.Map(list => list.Map(ProjectToViewModel).ToList()); |
||||
|
||||
return new PagedPlayoutsViewModel(count, page); |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
||||
#nullable disable |
||||
|
||||
namespace ErsatzTV.Infrastructure.MySql.Migrations |
||||
{ |
||||
/// <inheritdoc />
|
||||
public partial class Add_ChannelSortNumber : Migration |
||||
{ |
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.AddColumn<double>( |
||||
name: "SortNumber", |
||||
table: "Channel", |
||||
type: "double", |
||||
nullable: false, |
||||
defaultValue: 0.0); |
||||
|
||||
migrationBuilder.Sql( |
||||
@"UPDATE `Channel`
|
||||
SET `SortNumber` = CAST(`Number` AS DECIMAL(10,2)) |
||||
WHERE `Number` IS NOT NULL AND TRIM(`Number`) != ''");
|
||||
} |
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.DropColumn( |
||||
name: "SortNumber", |
||||
table: "Channel"); |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
||||
#nullable disable |
||||
|
||||
namespace ErsatzTV.Infrastructure.Sqlite.Migrations |
||||
{ |
||||
/// <inheritdoc />
|
||||
public partial class Add_ChannelSortNumber : Migration |
||||
{ |
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.AddColumn<double>( |
||||
name: "SortNumber", |
||||
table: "Channel", |
||||
type: "REAL", |
||||
nullable: false, |
||||
defaultValue: 0.0); |
||||
|
||||
migrationBuilder.Sql( |
||||
@"UPDATE `Channel`
|
||||
SET `SortNumber` = CAST(`Number` AS REAL) |
||||
WHERE `Number` IS NOT NULL AND TRIM(`Number`) != ''");
|
||||
} |
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder) |
||||
{ |
||||
migrationBuilder.DropColumn( |
||||
name: "SortNumber", |
||||
table: "Channel"); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue