Browse Source

simplify logic

pull/39/head
Jason Dove 5 years ago
parent
commit
c4cf23a93f
  1. 9
      ErsatzTV.Application/MediaCollections/CollectionUpdateResult.cs
  2. 4
      ErsatzTV.Application/MediaCollections/Commands/AddEpisodeToCollection.cs
  3. 28
      ErsatzTV.Application/MediaCollections/Commands/AddEpisodeToCollectionHandler.cs
  4. 4
      ErsatzTV.Application/MediaCollections/Commands/AddMovieCollection.cs
  5. 27
      ErsatzTV.Application/MediaCollections/Commands/AddMovieToCollectionHandler.cs
  6. 4
      ErsatzTV.Application/MediaCollections/Commands/AddSeasonToCollection.cs
  7. 27
      ErsatzTV.Application/MediaCollections/Commands/AddSeasonToCollectionHandler.cs
  8. 4
      ErsatzTV.Application/MediaCollections/Commands/AddShowToCollection.cs
  9. 26
      ErsatzTV.Application/MediaCollections/Commands/AddShowToCollectionHandler.cs
  10. 3
      ErsatzTV.Application/MediaCollections/Commands/RemoveItemsFromCollection.cs
  11. 26
      ErsatzTV.Application/MediaCollections/Commands/RemoveItemsFromCollectionHandler.cs
  12. 13
      ErsatzTV/Pages/CollectionItems.razor
  13. 16
      ErsatzTV/Pages/MovieList.razor
  14. 24
      ErsatzTV/Pages/Search.razor
  15. 13
      ErsatzTV/Pages/TelevisionEpisodeList.razor
  16. 13
      ErsatzTV/Pages/TelevisionSeasonList.razor
  17. 13
      ErsatzTV/Pages/TelevisionShowList.razor

9
ErsatzTV.Application/MediaCollections/CollectionUpdateResult.cs

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace ErsatzTV.Application.MediaCollections
{
public class CollectionUpdateResult
{
public List<int> ModifiedPlayoutIds { get; set; }
}
}

4
ErsatzTV.Application/MediaCollections/Commands/AddEpisodeToCollection.cs

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
using ErsatzTV.Core;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public record AddEpisodeToCollection
(int CollectionId, int EpisodeId) : IRequest<Either<BaseError, CollectionUpdateResult>>;
public record AddEpisodeToCollection(int CollectionId, int EpisodeId) : MediatR.IRequest<Either<BaseError, Unit>>;
}

28
ErsatzTV.Application/MediaCollections/Commands/AddEpisodeToCollectionHandler.cs

@ -1,46 +1,50 @@ @@ -1,46 +1,50 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Core;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public class
AddEpisodeToCollectionHandler : IRequestHandler<AddEpisodeToCollection,
Either<BaseError, CollectionUpdateResult>>
AddEpisodeToCollectionHandler : MediatR.IRequestHandler<AddEpisodeToCollection, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IMediaCollectionRepository _mediaCollectionRepository;
private readonly ITelevisionRepository _televisionRepository;
public AddEpisodeToCollectionHandler(
IMediaCollectionRepository mediaCollectionRepository,
ITelevisionRepository televisionRepository)
ITelevisionRepository televisionRepository,
ChannelWriter<IBackgroundServiceRequest> channel)
{
_mediaCollectionRepository = mediaCollectionRepository;
_televisionRepository = televisionRepository;
_channel = channel;
}
public Task<Either<BaseError, CollectionUpdateResult>> Handle(
public Task<Either<BaseError, Unit>> Handle(
AddEpisodeToCollection request,
CancellationToken cancellationToken) =>
Validate(request)
.MapT(_ => ApplyAddTelevisionEpisodeRequest(request))
.Bind(v => v.ToEitherAsync());
private async Task<CollectionUpdateResult> ApplyAddTelevisionEpisodeRequest(AddEpisodeToCollection request)
private async Task<Unit> ApplyAddTelevisionEpisodeRequest(AddEpisodeToCollection request)
{
var result = new CollectionUpdateResult();
if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.EpisodeId))
{
result.ModifiedPlayoutIds =
await _mediaCollectionRepository.PlayoutIdsUsingCollection(request.CollectionId);
// rebuild all playouts that use this collection
foreach (int playoutId in await _mediaCollectionRepository
.PlayoutIdsUsingCollection(request.CollectionId))
{
await _channel.WriteAsync(new BuildPlayout(playoutId, true));
}
}
return result;
return Unit.Default;
}
private async Task<Validation<BaseError, Unit>> Validate(AddEpisodeToCollection request) =>

4
ErsatzTV.Application/MediaCollections/Commands/AddMovieCollection.cs

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
using ErsatzTV.Core;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public record AddMovieToCollection
(int CollectionId, int MovieId) : IRequest<Either<BaseError, CollectionUpdateResult>>;
public record AddMovieToCollection(int CollectionId, int MovieId) : MediatR.IRequest<Either<BaseError, Unit>>;
}

27
ErsatzTV.Application/MediaCollections/Commands/AddMovieToCollectionHandler.cs

@ -1,46 +1,51 @@ @@ -1,46 +1,51 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public class
AddMovieToCollectionHandler : IRequestHandler<AddMovieToCollection, Either<BaseError, CollectionUpdateResult>>
AddMovieToCollectionHandler : MediatR.IRequestHandler<AddMovieToCollection, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IMediaCollectionRepository _mediaCollectionRepository;
private readonly IMovieRepository _movieRepository;
public AddMovieToCollectionHandler(
IMediaCollectionRepository mediaCollectionRepository,
IMovieRepository movieRepository)
IMovieRepository movieRepository,
ChannelWriter<IBackgroundServiceRequest> channel)
{
_mediaCollectionRepository = mediaCollectionRepository;
_movieRepository = movieRepository;
_channel = channel;
}
public Task<Either<BaseError, CollectionUpdateResult>> Handle(
public Task<Either<BaseError, Unit>> Handle(
AddMovieToCollection request,
CancellationToken cancellationToken) =>
Validate(request)
.MapT(_ => ApplyAddMoviesRequest(request))
.Bind(v => v.ToEitherAsync());
private async Task<CollectionUpdateResult> ApplyAddMoviesRequest(AddMovieToCollection request)
private async Task<Unit> ApplyAddMoviesRequest(AddMovieToCollection request)
{
var result = new CollectionUpdateResult();
if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.MovieId))
{
result.ModifiedPlayoutIds =
await _mediaCollectionRepository.PlayoutIdsUsingCollection(request.CollectionId);
// rebuild all playouts that use this collection
foreach (int playoutId in await _mediaCollectionRepository
.PlayoutIdsUsingCollection(request.CollectionId))
{
await _channel.WriteAsync(new BuildPlayout(playoutId, true));
}
}
return result;
return Unit.Default;
}
private async Task<Validation<BaseError, Unit>> Validate(AddMovieToCollection request) =>

4
ErsatzTV.Application/MediaCollections/Commands/AddSeasonToCollection.cs

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
using ErsatzTV.Core;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public record AddSeasonToCollection
(int CollectionId, int SeasonId) : IRequest<Either<BaseError, CollectionUpdateResult>>;
public record AddSeasonToCollection(int CollectionId, int SeasonId) : MediatR.IRequest<Either<BaseError, Unit>>;
}

27
ErsatzTV.Application/MediaCollections/Commands/AddSeasonToCollectionHandler.cs

@ -1,46 +1,51 @@ @@ -1,46 +1,51 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public class
AddSeasonToCollectionHandler : IRequestHandler<AddSeasonToCollection, Either<BaseError, CollectionUpdateResult>>
AddSeasonToCollectionHandler : MediatR.IRequestHandler<AddSeasonToCollection, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IMediaCollectionRepository _mediaCollectionRepository;
private readonly ITelevisionRepository _televisionRepository;
public AddSeasonToCollectionHandler(
IMediaCollectionRepository mediaCollectionRepository,
ITelevisionRepository televisionRepository)
ITelevisionRepository televisionRepository,
ChannelWriter<IBackgroundServiceRequest> channel)
{
_mediaCollectionRepository = mediaCollectionRepository;
_televisionRepository = televisionRepository;
_channel = channel;
}
public Task<Either<BaseError, CollectionUpdateResult>> Handle(
public Task<Either<BaseError, Unit>> Handle(
AddSeasonToCollection request,
CancellationToken cancellationToken) =>
Validate(request)
.MapT(_ => ApplyAddTelevisionSeasonRequest(request))
.Bind(v => v.ToEitherAsync());
private async Task<CollectionUpdateResult> ApplyAddTelevisionSeasonRequest(AddSeasonToCollection request)
private async Task<Unit> ApplyAddTelevisionSeasonRequest(AddSeasonToCollection request)
{
var result = new CollectionUpdateResult();
if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.SeasonId))
{
result.ModifiedPlayoutIds =
await _mediaCollectionRepository.PlayoutIdsUsingCollection(request.CollectionId);
// rebuild all playouts that use this collection
foreach (int playoutId in await _mediaCollectionRepository
.PlayoutIdsUsingCollection(request.CollectionId))
{
await _channel.WriteAsync(new BuildPlayout(playoutId, true));
}
}
return result;
return Unit.Default;
}
private async Task<Validation<BaseError, Unit>> Validate(AddSeasonToCollection request) =>

4
ErsatzTV.Application/MediaCollections/Commands/AddShowToCollection.cs

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
using ErsatzTV.Core;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public record AddShowToCollection
(int CollectionId, int ShowId) : IRequest<Either<BaseError, CollectionUpdateResult>>;
public record AddShowToCollection(int CollectionId, int ShowId) : MediatR.IRequest<Either<BaseError, Unit>>;
}

26
ErsatzTV.Application/MediaCollections/Commands/AddShowToCollectionHandler.cs

@ -1,43 +1,49 @@ @@ -1,43 +1,49 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
using Unit = LanguageExt.Unit;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public class
AddShowToCollectionHandler : IRequestHandler<AddShowToCollection, Either<BaseError, CollectionUpdateResult>>
public class AddShowToCollectionHandler : MediatR.IRequestHandler<AddShowToCollection, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IMediaCollectionRepository _mediaCollectionRepository;
private readonly ITelevisionRepository _televisionRepository;
public AddShowToCollectionHandler(
IMediaCollectionRepository mediaCollectionRepository,
ITelevisionRepository televisionRepository)
ITelevisionRepository televisionRepository,
ChannelWriter<IBackgroundServiceRequest> channel)
{
_mediaCollectionRepository = mediaCollectionRepository;
_televisionRepository = televisionRepository;
_channel = channel;
}
public Task<Either<BaseError, CollectionUpdateResult>> Handle(
public Task<Either<BaseError, Unit>> Handle(
AddShowToCollection request,
CancellationToken cancellationToken) =>
Validate(request)
.MapT(_ => ApplyAddTelevisionShowRequest(request))
.Bind(v => v.ToEitherAsync());
private async Task<CollectionUpdateResult> ApplyAddTelevisionShowRequest(AddShowToCollection request)
private async Task<Unit> ApplyAddTelevisionShowRequest(AddShowToCollection request)
{
var result = new CollectionUpdateResult();
var result = new Unit();
if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.ShowId))
{
result.ModifiedPlayoutIds =
await _mediaCollectionRepository.PlayoutIdsUsingCollection(request.CollectionId);
// rebuild all playouts that use this collection
foreach (int playoutId in await _mediaCollectionRepository
.PlayoutIdsUsingCollection(request.CollectionId))
{
await _channel.WriteAsync(new BuildPlayout(playoutId, true));
}
}
return result;

3
ErsatzTV.Application/MediaCollections/Commands/RemoveItemsFromCollection.cs

@ -1,11 +1,10 @@ @@ -1,11 +1,10 @@
using System.Collections.Generic;
using ErsatzTV.Core;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public record RemoveItemsFromCollection(int MediaCollectionId) : IRequest<Either<BaseError, CollectionUpdateResult>>
public record RemoveItemsFromCollection(int MediaCollectionId) : MediatR.IRequest<Either<BaseError, Unit>>
{
public List<int> MediaItemIds { get; set; } = new();
}

26
ErsatzTV.Application/MediaCollections/Commands/RemoveItemsFromCollectionHandler.cs

@ -1,32 +1,37 @@ @@ -1,32 +1,37 @@
using System.Linq;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
namespace ErsatzTV.Application.MediaCollections.Commands
{
public class
RemoveItemsFromCollectionHandler : IRequestHandler<RemoveItemsFromCollection,
Either<BaseError, CollectionUpdateResult>>
RemoveItemsFromCollectionHandler : MediatR.IRequestHandler<RemoveItemsFromCollection, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IMediaCollectionRepository _mediaCollectionRepository;
public RemoveItemsFromCollectionHandler(
IMediaCollectionRepository mediaCollectionRepository) =>
IMediaCollectionRepository mediaCollectionRepository,
ChannelWriter<IBackgroundServiceRequest> channel)
{
_mediaCollectionRepository = mediaCollectionRepository;
_channel = channel;
}
public Task<Either<BaseError, CollectionUpdateResult>> Handle(
public Task<Either<BaseError, Unit>> Handle(
RemoveItemsFromCollection request,
CancellationToken cancellationToken) =>
Validate(request)
.MapT(collection => ApplyRemoveItemsRequest(request, collection))
.Bind(v => v.ToEitherAsync());
private async Task<CollectionUpdateResult> ApplyRemoveItemsRequest(
private async Task<Unit> ApplyRemoveItemsRequest(
RemoveItemsFromCollection request,
Collection collection)
{
@ -36,13 +41,16 @@ namespace ErsatzTV.Application.MediaCollections.Commands @@ -36,13 +41,16 @@ namespace ErsatzTV.Application.MediaCollections.Commands
itemsToRemove.ForEach(m => collection.MediaItems.Remove(m));
var result = new CollectionUpdateResult();
if (itemsToRemove.Any() && await _mediaCollectionRepository.Update(collection))
{
result.ModifiedPlayoutIds = await _mediaCollectionRepository.PlayoutIdsUsingCollection(collection.Id);
// rebuild all playouts that use this collection
foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingCollection(collection.Id))
{
await _channel.WriteAsync(new BuildPlayout(playoutId, true));
}
}
return result;
return Unit.Default;
}
private Task<Validation<BaseError, Collection>> Validate(

13
ErsatzTV/Pages/CollectionItems.razor

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
@page "/media/collections/{Id:int}"
@using ErsatzTV.Application.MediaCards
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@inject NavigationManager NavigationManager
@inject IMediator Mediator
@inject ILogger<CollectionItems> Logger
@ -164,16 +162,7 @@ @@ -164,16 +162,7 @@
DialogResult result = await dialog.Result;
if (!result.Cancelled)
{
Either<BaseError, CollectionUpdateResult> removeResult = await Mediator.Send(request);
await removeResult.Match(
async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
},
_ => Task.CompletedTask);
await Mediator.Send(request);
await RefreshData();
}
}

16
ErsatzTV/Pages/MovieList.razor

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@using Unit = LanguageExt.Unit
@inject ILogger<MovieList> Logger
@inject ISnackbar Snackbar
@inject IMediator Mediator
@ -74,22 +74,14 @@ @@ -74,22 +74,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddMovieToCollection(collection.Id, movie.MovieId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
await addResult.Match(
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding movie to collection: {error.Value}");
Logger.LogError("Unexpected error adding movie to collection: {Error}", error.Value);
return Task.CompletedTask;
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {movie.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {movie.Title} to collection {collection.Name}", Severity.Success));
}
}
}

24
ErsatzTV/Pages/Search.razor

@ -3,9 +3,9 @@ @@ -3,9 +3,9 @@
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@using Microsoft.AspNetCore.WebUtilities
@using Microsoft.Extensions.Primitives
@using Unit = LanguageExt.Unit
@inject NavigationManager NavigationManager
@inject IMediator Mediator
@inject ILogger<Search> Logger
@ -75,21 +75,14 @@ @@ -75,21 +75,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddMovieToCollection(collection.Id, movie.MovieId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding movie to collection: {error.Value}");
Logger.LogError("Unexpected error adding movie to collection: {Error}", error.Value);
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {movie.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {movie.Title} to collection {collection.Name}", Severity.Success));
}
}
@ -103,21 +96,14 @@ @@ -103,21 +96,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddShowToCollection(collection.Id, show.TelevisionShowId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding show to collection: {error.Value}");
Logger.LogError("Unexpected error adding show to collection: {Error}", error.Value);
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {show.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {show.Title} to collection {collection.Name}", Severity.Success));
}
}
}

13
ErsatzTV/Pages/TelevisionEpisodeList.razor

@ -5,9 +5,9 @@ @@ -5,9 +5,9 @@
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@using ErsatzTV.Application.ProgramSchedules
@using ErsatzTV.Application.ProgramSchedules.Commands
@using Unit = LanguageExt.Unit
@inject IMediator Mediator
@inject ILogger<TelevisionEpisodeList> Logger
@inject ISnackbar Snackbar
@ -136,21 +136,14 @@ @@ -136,21 +136,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddEpisodeToCollection(collection.Id, episode.EpisodeId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding episode to collection: {error.Value}");
Logger.LogError("Unexpected error adding episode to collection: {Error}", error.Value);
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {episode.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {episode.Title} to collection {collection.Name}", Severity.Success));
}
}
}

13
ErsatzTV/Pages/TelevisionSeasonList.razor

@ -5,9 +5,9 @@ @@ -5,9 +5,9 @@
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@using ErsatzTV.Application.ProgramSchedules
@using ErsatzTV.Application.ProgramSchedules.Commands
@using Unit = LanguageExt.Unit
@inject IMediator Mediator
@inject ILogger<TelevisionSeasonList> Logger
@inject ISnackbar Snackbar
@ -130,21 +130,14 @@ @@ -130,21 +130,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddSeasonToCollection(collection.Id, season.TelevisionSeasonId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding season to collection: {error.Value}");
Logger.LogError("Unexpected error adding season to collection: {Error}", error.Value);
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {season.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {season.Title} to collection {collection.Name}", Severity.Success));
}
}
}

13
ErsatzTV/Pages/TelevisionShowList.razor

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
@using ErsatzTV.Application.MediaCards.Queries
@using ErsatzTV.Application.MediaCollections
@using ErsatzTV.Application.MediaCollections.Commands
@using ErsatzTV.Application.Playouts.Commands
@using Unit = LanguageExt.Unit
@inject ILogger<TelevisionShowList> Logger
@inject ISnackbar Snackbar
@inject IMediator Mediator
@ -70,21 +70,14 @@ @@ -70,21 +70,14 @@
if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
{
var request = new AddShowToCollection(collection.Id, show.TelevisionShowId);
Either<BaseError, CollectionUpdateResult> addResult = await Mediator.Send(request);
Either<BaseError, Unit> addResult = await Mediator.Send(request);
addResult.Match(
Left: error =>
{
Snackbar.Add($"Unexpected error adding show to collection: {error.Value}");
Logger.LogError("Unexpected error adding show to collection: {Error}", error.Value);
},
Right: async collectionUpdateResult =>
{
foreach (int playoutId in collectionUpdateResult.ModifiedPlayoutIds)
{
await Channel.WriteAsync(new BuildPlayout(playoutId, true));
}
Snackbar.Add($"Added {show.Title} to collection {collection.Name}", Severity.Success);
});
Right: _ => Snackbar.Add($"Added {show.Title} to collection {collection.Name}", Severity.Success));
}
}
}

Loading…
Cancel
Save