feat: add queries for faculty
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m18s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m18s
This commit is contained in:
@ -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.Faculty.Queries.GetFacultyList;
|
||||
|
||||
public class GetFacultyListQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyListQuery, FacultyListVm>
|
||||
{
|
||||
public async Task<FacultyListVm> Handle(GetFacultyListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.Faculties.OrderBy(f => f.Id).Select(f => new FacultyLookupDto()
|
||||
{
|
||||
Id = f.Id,
|
||||
Name = f.Name,
|
||||
CampusId = f.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 FacultyListVm
|
||||
{
|
||||
Faculties = result
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user