feat: add queries for lecture hall
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m42s

This commit is contained in:
Polianin Nikita 2024-02-16 22:51:26 +03:00
parent ce3bd23673
commit a00dc8ccd6
7 changed files with 144 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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>();
}

View File

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