namespace CMSMicroservice.Application.TagCQ.Queries.GetTag;
public class GetTagQueryHandler : IRequestHandler<GetTagQuery, GetTagResponseDto>
{
    private readonly IApplicationDbContext _context;

    public GetTagQueryHandler(IApplicationDbContext context)
    {
        _context = context;
    }

    public async Task<GetTagResponseDto> Handle(GetTagQuery request,
        CancellationToken cancellationToken)
    {
        var response = await _context.Tags
            .AsNoTracking()
            .Where(x => x.Id == request.Id)
            .ProjectToType<GetTagResponseDto>()
            .FirstOrDefaultAsync(cancellationToken);

        return response ?? throw new NotFoundException(nameof(Tag), request.Id);
    }
}

