Add queries #8
@ -0,0 +1,8 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
|
||||||
|
|
||||||
|
public class GetLectureHallInfoQuery : IRequest<LectureHallInfoVm>
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
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.LectureHall.Queries.GetLectureHallDetails;
|
||||||
|
|
||||||
|
public class GetLectureHallInfoQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallInfoQuery, LectureHallInfoVm>
|
||||||
|
{
|
||||||
|
public async Task<LectureHallInfoVm> Handle(GetLectureHallInfoQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var lectureHall = await dbContext.LectureHalls
|
||||||
|
.Include(l => l.Campus)
|
||||||
|
.FirstOrDefaultAsync(l => l.Id == request.Id, cancellationToken)
|
||||||
|
?? throw new NotFoundException(typeof(Domain.Schedule.LectureHall), request.Id);
|
||||||
|
|
||||||
|
return new LectureHallInfoVm()
|
||||||
|
{
|
||||||
|
Id = lectureHall.Id,
|
||||||
|
Name = lectureHall.Name,
|
||||||
|
CampusId = lectureHall.CampusId,
|
||||||
|
CampusCode = lectureHall.Campus?.CodeName,
|
||||||
|
CampusName = lectureHall.Campus?.FullName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents disciplines.
|
||||||
|
/// </summary>
|
||||||
|
public class LectureHallInfoVm
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier for the lecture hall.
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the lecture hall.
|
||||||
|
/// </summary>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ID indicating the lecture hall's affiliation to the campus.
|
||||||
|
/// </summary>
|
||||||
|
public int CampusId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Campus name indicating the lecture hall's affiliation to the campus.
|
||||||
|
/// </summary>
|
||||||
|
public string? CampusName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Campus code indicating the lecture hall's affiliation to the campus.
|
||||||
|
/// </summary>
|
||||||
|
public string? CampusCode { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||||
|
|
||||||
|
public class GetLectureHallListQuery : IRequest<LectureHallListVm>
|
||||||
|
{
|
||||||
|
public int? Page { get; set; }
|
||||||
|
public int? PageSize { get; set; }
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||||
|
|
||||||
|
public class GetLectureHallListQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallListQuery, LectureHallListVm>
|
||||||
|
{
|
||||||
|
public async Task<LectureHallListVm> Handle(GetLectureHallListQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var dtos = dbContext.LectureHalls.OrderBy(l => l.Id).Select(l => new LectureHallLookupDto()
|
||||||
|
{
|
||||||
|
Id = l.Id,
|
||||||
|
Name = l.Name,
|
||||||
|
CampusId = l.CampusId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (request is { PageSize: not null, Page: not null })
|
||||||
|
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||||
|
|
||||||
|
var result = await dtos.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return new LectureHallListVm
|
||||||
|
{
|
||||||
|
LectureHalls = result
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a view model containing multiple disciplines name.
|
||||||
|
/// </summary>
|
||||||
|
public class LectureHallListVm
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The list of lecture hall.
|
||||||
|
/// </summary>
|
||||||
|
public IList<LectureHallLookupDto> LectureHalls { get; set; } = new List<LectureHallLookupDto>();
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents lecture halls.
|
||||||
|
/// </summary>
|
||||||
|
public class LectureHallLookupDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier for the lecture hall.
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the lecture hall.
|
||||||
|
/// </summary>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ID indicating the lecture hall's affiliation to the campus.
|
||||||
|
/// </summary>
|
||||||
|
public int CampusId { get; set; }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user