2024-02-16 22:52:36 +03:00
|
|
|
|
using MediatR;
|
2024-01-28 04:31:18 +03:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
2024-02-16 22:52:36 +03:00
|
|
|
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-01-28 04:31:18 +03:00
|
|
|
|
|
|
|
|
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
|
|
|
|
|
|
|
|
|
public class GetCampusDetailsQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusDetailsQuery, CampusDetailsVm>
|
|
|
|
|
{
|
|
|
|
|
public async Task<CampusDetailsVm> Handle(GetCampusDetailsQuery request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var campus = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), request.Id);
|
|
|
|
|
|
|
|
|
|
return new CampusDetailsVm()
|
|
|
|
|
{
|
|
|
|
|
Id = campus.Id,
|
|
|
|
|
CodeName = campus.CodeName,
|
|
|
|
|
FullName = campus.FullName,
|
|
|
|
|
Address = campus.Address
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|