MireaBackend/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQueryHandler.cs
Polianin Nikita a1a83ce2e6
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m28s
feat: add queries for the discipline
2024-01-28 05:59:48 +03:00

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,
};
}
}