22 lines
920 B
C#
22 lines
920 B
C#
|
using MediatR;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
|||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
|
|||
|
|
|||
|
public class GetDisciplineInfoQueryHandler(IDisciplineDbContext dbContext) : IRequestHandler<GetDisciplineInfoQuery, DisciplineInfoVm>
|
|||
|
{
|
|||
|
public async Task<DisciplineInfoVm> Handle(GetDisciplineInfoQuery request, CancellationToken cancellationToken)
|
|||
|
{
|
|||
|
var discipline = await dbContext.Disciplines.FirstOrDefaultAsync(d => d.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Discipline), request.Id);
|
|||
|
|
|||
|
return new DisciplineInfoVm()
|
|||
|
{
|
|||
|
Id = discipline.Id,
|
|||
|
Name = discipline.Name,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|