mirror of https://github.com/ErsatzTV/ErsatzTV.git
8 changed files with 114 additions and 1 deletions
@ -0,0 +1,7 @@ |
|||||||
|
using ErsatzTV.Core; |
||||||
|
using LanguageExt; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Libraries.Commands |
||||||
|
{ |
||||||
|
public record DeleteLocalLibraryPath(int LocalLibraryPathId) : MediatR.IRequest<Either<BaseError, Unit>>; |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
using System.Threading; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using ErsatzTV.Core; |
||||||
|
using ErsatzTV.Core.Domain; |
||||||
|
using ErsatzTV.Core.Interfaces.Repositories; |
||||||
|
using LanguageExt; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Libraries.Commands |
||||||
|
{ |
||||||
|
public class |
||||||
|
DeleteLocalLibraryPathHandler : MediatR.IRequestHandler<DeleteLocalLibraryPath, Either<BaseError, Unit>> |
||||||
|
{ |
||||||
|
private readonly ILibraryRepository _libraryRepository; |
||||||
|
|
||||||
|
public DeleteLocalLibraryPathHandler(ILibraryRepository libraryRepository) => |
||||||
|
_libraryRepository = libraryRepository; |
||||||
|
|
||||||
|
public Task<Either<BaseError, Unit>> Handle( |
||||||
|
DeleteLocalLibraryPath request, |
||||||
|
CancellationToken cancellationToken) => |
||||||
|
MediaSourceMustExist(request) |
||||||
|
.MapT(DoDeletion) |
||||||
|
.Bind(t => t.ToEitherAsync()); |
||||||
|
|
||||||
|
private Task<Unit> DoDeletion(LibraryPath libraryPath) => |
||||||
|
_libraryRepository.DeleteLocalPath(libraryPath.Id).ToUnit(); |
||||||
|
|
||||||
|
private async Task<Validation<BaseError, LibraryPath>> MediaSourceMustExist(DeleteLocalLibraryPath request) => |
||||||
|
(await _libraryRepository.GetPath(request.LocalLibraryPathId)) |
||||||
|
.HeadOrNone() |
||||||
|
.ToValidation<BaseError>( |
||||||
|
$"Local library path {request.LocalLibraryPathId} does not exist."); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
using MediatR; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Libraries.Queries |
||||||
|
{ |
||||||
|
public record CountMediaItemsByLibraryPath(int LibraryPathId) : IRequest<int>; |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
using System.Threading; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using ErsatzTV.Core.Interfaces.Repositories; |
||||||
|
using MediatR; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Libraries.Queries |
||||||
|
{ |
||||||
|
public class CountMediaItemsByLibraryPathHandler : IRequestHandler<CountMediaItemsByLibraryPath, int> |
||||||
|
{ |
||||||
|
private readonly ILibraryRepository _libraryRepository; |
||||||
|
|
||||||
|
public CountMediaItemsByLibraryPathHandler(ILibraryRepository libraryRepository) => |
||||||
|
_libraryRepository = libraryRepository; |
||||||
|
|
||||||
|
public Task<int> Handle(CountMediaItemsByLibraryPath request, CancellationToken cancellationToken) => |
||||||
|
_libraryRepository.CountMediaItemsByPath(request.LibraryPathId); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue