41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Asp.Versioning;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
|
using Mirea.Api.Dto.Responses;
|
|
using Mirea.Api.Endpoint.Common.Attributes;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mirea.Api.Endpoint.Controllers.V1;
|
|
|
|
[ApiVersion("1.0")]
|
|
[CacheMaxAge(true)]
|
|
public class FacultyController(IMediator mediator) : BaseController
|
|
{
|
|
/// <summary>
|
|
/// Gets a paginated list of faculties.
|
|
/// </summary>
|
|
/// <param name="page">Page number. Start from 0.</param>
|
|
/// <param name="pageSize">Number of items per page.</param>
|
|
/// <returns>Paginated list of faculties.</returns>
|
|
[HttpGet]
|
|
[BadRequestResponse]
|
|
public async Task<ActionResult<List<FacultyResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
|
|
{
|
|
var result = await mediator.Send(new GetFacultyListQuery()
|
|
{
|
|
Page = page,
|
|
PageSize = pageSize
|
|
});
|
|
|
|
return Ok(result.Faculties
|
|
.Select(f => new FacultyResponse()
|
|
{
|
|
Id = f.Id,
|
|
Name = f.Name
|
|
})
|
|
);
|
|
}
|
|
} |