feat: add lesson type controller
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Queries.GetTypeOfOccupationList;
|
||||
|
||||
public class GetTypeOfOccupationListQuery : IRequest<TypeOfOccupationListVm>
|
||||
{
|
||||
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.TypeOfOccupation.Queries.GetTypeOfOccupationList;
|
||||
|
||||
public class GetTypeOfOccupationListQueryHandler(ITypeOfOccupationDbContext dbContext) : IRequestHandler<GetTypeOfOccupationListQuery, TypeOfOccupationListVm>
|
||||
{
|
||||
public async Task<TypeOfOccupationListVm> Handle(GetTypeOfOccupationListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.TypeOfOccupations.OrderBy(t => t.Id)
|
||||
.Select(t => new TypeOfOccupationLookupDto()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.ShortName
|
||||
});
|
||||
|
||||
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 TypeOfOccupationListVm
|
||||
{
|
||||
TypeOfOccupations = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Queries.GetTypeOfOccupationList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple type of occupations.
|
||||
/// </summary>
|
||||
public class TypeOfOccupationListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of type of occupations.
|
||||
/// </summary>
|
||||
public IEnumerable<TypeOfOccupationLookupDto> TypeOfOccupations { get; set; } = [];
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Queries.GetTypeOfOccupationList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents type of occupations.
|
||||
/// </summary>
|
||||
public class TypeOfOccupationLookupDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the occupation.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the occupation.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
}
|
Reference in New Issue
Block a user