using AutobusApi.Application.Common.Exceptions; using AutobusApi.Application.Common.Interfaces; using AutoMapper; using MediatR; using Microsoft.EntityFrameworkCore; namespace AutobusApi.Application.TicketGroups.Queries.GetTicketGroup; public class GetTicketGroupQueryHandler : IRequestHandler { private readonly IApplicationDbContext _dbContext; private readonly IMapper _mapper; public GetTicketGroupQueryHandler( IApplicationDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; } public async Task Handle( GetTicketGroupQuery request, CancellationToken cancellationToken) { var ticketGroup = await _dbContext.TicketGroups .SingleOrDefaultAsync(c => c.Id == request.Id); if (ticketGroup == null) { throw new NotFoundException(); } return _mapper.Map(ticketGroup); } }