Polianin Nikita
ce3bd23673
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m18s
27 lines
1.0 KiB
C#
27 lines
1.0 KiB
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.Faculty.Queries.GetFacultyDetails;
|
|
|
|
public class GetFacultyInfoQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyInfoQuery, FacultyInfoVm>
|
|
{
|
|
public async Task<FacultyInfoVm> Handle(GetFacultyInfoQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var faculty = await dbContext.Faculties
|
|
.Include(f => f.Campus)
|
|
.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Faculty), request.Id);
|
|
|
|
return new FacultyInfoVm()
|
|
{
|
|
Id = faculty.Id,
|
|
Name = faculty.Name,
|
|
CampusId = faculty.CampusId,
|
|
CampusName = faculty.Campus?.FullName,
|
|
CampusCode = faculty.Campus?.CodeName
|
|
};
|
|
}
|
|
} |