Files
ersatztv/ErsatzTV.Application/MediaCollections/Queries/GetCollectionByIdHandler.cs
T
Jason DoveandGitHub 1c07df5bc3 use cancellation tokens in many places (#2350)
* use cancellation tokens everywhere

* more cancellation tokens
2025-08-27 03:20:35 +00:00

27 lines
1004 B
C#

using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
using static ErsatzTV.Application.MediaCollections.Mapper;
namespace ErsatzTV.Application.MediaCollections;
public class GetCollectionByIdHandler :
IRequestHandler<GetCollectionById, Option<MediaCollectionViewModel>>
{
private readonly IDbContextFactory<TvContext> _dbContextFactory;
public GetCollectionByIdHandler(IDbContextFactory<TvContext> dbContextFactory) =>
_dbContextFactory = dbContextFactory;
public async Task<Option<MediaCollectionViewModel>> Handle(
GetCollectionById request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
return await dbContext.Collections
.AsNoTracking()
.SelectOneAsync(c => c.Id, c => c.Id == request.Id, cancellationToken)
.MapT(ProjectToViewModel);
}
}