mirror of https://github.com/ErsatzTV/ErsatzTV.git
10 changed files with 2476 additions and 31 deletions
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
using ErsatzTV.Core; |
||||
using LanguageExt; |
||||
|
||||
namespace ErsatzTV.Application.Configuration.Commands |
||||
{ |
||||
public record UpdateLibraryRefreshInterval(int LibraryRefreshInterval) : MediatR.IRequest<Either<BaseError, Unit>>; |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using ErsatzTV.Core; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Interfaces.Repositories; |
||||
using LanguageExt; |
||||
using static LanguageExt.Prelude; |
||||
|
||||
namespace ErsatzTV.Application.Configuration.Commands |
||||
{ |
||||
public class |
||||
UpdateLibraryRefreshIntervalHandler : MediatR.IRequestHandler<UpdateLibraryRefreshInterval, |
||||
Either<BaseError, Unit>> |
||||
{ |
||||
private readonly IConfigElementRepository _configElementRepository; |
||||
|
||||
public UpdateLibraryRefreshIntervalHandler(IConfigElementRepository configElementRepository) => |
||||
_configElementRepository = configElementRepository; |
||||
|
||||
public Task<Either<BaseError, Unit>> Handle( |
||||
UpdateLibraryRefreshInterval request, |
||||
CancellationToken cancellationToken) => |
||||
Validate(request) |
||||
.MapT(_ => Upsert(ConfigElementKey.LibraryRefreshInterval, request.LibraryRefreshInterval.ToString())) |
||||
.Bind(v => v.ToEitherAsync()); |
||||
|
||||
private Task<Validation<BaseError, Unit>> Validate(UpdateLibraryRefreshInterval request) => |
||||
Optional(request.LibraryRefreshInterval) |
||||
.Filter(lri => lri > 0) |
||||
.Map(_ => Unit.Default) |
||||
.ToValidation<BaseError>("Tuner count must be greater than zero") |
||||
.AsTask(); |
||||
|
||||
private Task<Unit> Upsert(ConfigElementKey key, string value) => |
||||
_configElementRepository.Get(key).Match( |
||||
ce => |
||||
{ |
||||
ce.Value = value; |
||||
return _configElementRepository.Update(ce); |
||||
}, |
||||
() => |
||||
{ |
||||
var ce = new ConfigElement { Key = key.Key, Value = value }; |
||||
return _configElementRepository.Add(ce); |
||||
}).ToUnit(); |
||||
} |
||||
} |
||||
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
using MediatR; |
||||
|
||||
namespace ErsatzTV.Application.Configuration.Queries |
||||
{ |
||||
public record GetLibraryRefreshInterval : IRequest<int>; |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Interfaces.Repositories; |
||||
using LanguageExt; |
||||
using MediatR; |
||||
|
||||
namespace ErsatzTV.Application.Configuration.Queries |
||||
{ |
||||
public class GetLibraryRefreshIntervalHandler : IRequestHandler<GetLibraryRefreshInterval, int> |
||||
{ |
||||
private readonly IConfigElementRepository _configElementRepository; |
||||
|
||||
public GetLibraryRefreshIntervalHandler(IConfigElementRepository configElementRepository) => |
||||
_configElementRepository = configElementRepository; |
||||
|
||||
public Task<int> Handle(GetLibraryRefreshInterval request, CancellationToken cancellationToken) => |
||||
_configElementRepository.GetValue<int>(ConfigElementKey.LibraryRefreshInterval) |
||||
.Map(result => result.IfNone(6)); |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
||||
namespace ErsatzTV.Infrastructure.Migrations |
||||
{ |
||||
public partial class Add_LibraryRefreshInterval : Migration |
||||
{ |
||||
protected override void Up(MigrationBuilder migrationBuilder) => |
||||
migrationBuilder.Sql( |
||||
"INSERT INTO ConfigElement (Key, Value) VALUES ('scanner.library_refresh_interval', '6')"); |
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue