31 lines
1023 B
C#
31 lines
1023 B
C#
|
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.Group.Queries.GetGroupList;
|
|||
|
|
|||
|
public class GetGroupListQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupListQuery, GroupListVm>
|
|||
|
{
|
|||
|
public async Task<GroupListVm> Handle(GetGroupListQuery request, CancellationToken cancellationToken)
|
|||
|
{
|
|||
|
var dtos = dbContext.Groups.OrderBy(g => g.Id).Select(g => new GroupLookupDto()
|
|||
|
{
|
|||
|
Id = g.Id,
|
|||
|
Name = g.Name,
|
|||
|
FacultyId = g.FacultyId
|
|||
|
});
|
|||
|
|
|||
|
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 GroupListVm
|
|||
|
{
|
|||
|
Groups = result
|
|||
|
};
|
|||
|
}
|
|||
|
}
|