* rework television media * refactor poster saving * television and movie views are working again * remove dead code * use paper styling for all cards * add show poster, plot to seasons page * remove missing shows; cleanup interfaces * fix split show display (same show in different folders/sources) * add placeholder "add to schedule" button * no more duplicate television shows, even with the same show split across sources * stop releasing CLI for now * use season number as season placeholder * add television shows to collections * add television seasons to collections * add television episodes to collections * add movies to collections * remove movies, shows, seasons, episodes from collections * fix page width and menus * fix buffer size defaults * fix chronological episode ordering * allow deleting media collections * don't get stuck building a playout with an empty collection * schedule editing and playouts work again * minor cleanup * remove dead code * fix bugs with viewing movies as they are loading * add scanner tests; support nested movie folders * update collections docs * rearrange order of schedule items * add show and season to schedule * delete schedules that use legacy collections, reset all posters * move cleanup to new migration * load fallback metadata when nfo fails; don't require metadata in ui * update readme and screenshots
58 lines
2.5 KiB
C#
58 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using LanguageExt;
|
|
using MediatR;
|
|
using static ErsatzTV.Application.MediaCollections.Mapper;
|
|
using static LanguageExt.Prelude;
|
|
|
|
namespace ErsatzTV.Application.MediaCollections.Commands
|
|
{
|
|
public class CreateSimpleMediaCollectionHandler : IRequestHandler<CreateSimpleMediaCollection,
|
|
Either<BaseError, MediaCollectionViewModel>>
|
|
{
|
|
private readonly IMediaCollectionRepository _mediaCollectionRepository;
|
|
|
|
public CreateSimpleMediaCollectionHandler(IMediaCollectionRepository mediaCollectionRepository) =>
|
|
_mediaCollectionRepository = mediaCollectionRepository;
|
|
|
|
public Task<Either<BaseError, MediaCollectionViewModel>> Handle(
|
|
CreateSimpleMediaCollection request,
|
|
CancellationToken cancellationToken) =>
|
|
Validate(request).MapT(PersistCollection).Bind(v => v.ToEitherAsync());
|
|
|
|
private Task<MediaCollectionViewModel> PersistCollection(SimpleMediaCollection c) =>
|
|
_mediaCollectionRepository.Add(c).Map(ProjectToViewModel);
|
|
|
|
private Task<Validation<BaseError, SimpleMediaCollection>> Validate(CreateSimpleMediaCollection request) =>
|
|
ValidateName(request).MapT(
|
|
name => new SimpleMediaCollection
|
|
{
|
|
Name = name,
|
|
Movies = new List<MovieMediaItem>(),
|
|
TelevisionShows = new List<TelevisionShow>(),
|
|
TelevisionEpisodes = new List<TelevisionEpisodeMediaItem>(),
|
|
TelevisionSeasons = new List<TelevisionSeason>()
|
|
});
|
|
|
|
private async Task<Validation<BaseError, string>> ValidateName(CreateSimpleMediaCollection createCollection)
|
|
{
|
|
List<string> allNames = await _mediaCollectionRepository.GetSimpleMediaCollections()
|
|
.Map(list => list.Map(c => c.Name).ToList());
|
|
|
|
Validation<BaseError, string> result1 = createCollection.NotEmpty(c => c.Name)
|
|
.Bind(_ => createCollection.NotLongerThan(50)(c => c.Name));
|
|
|
|
var result2 = Optional(createCollection.Name)
|
|
.Filter(name => !allNames.Contains(name))
|
|
.ToValidation<BaseError>("Media collection name must be unique");
|
|
|
|
return (result1, result2).Apply((_, _) => createCollection.Name);
|
|
}
|
|
}
|
|
}
|