MireaBackend/Endpoint/Controllers/V1/FacultyController.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2024-09-18 06:00:07 +03:00
using Asp.Versioning;
using MediatR;
2024-02-16 23:57:05 +03:00
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;
2024-05-28 07:09:40 +03:00
namespace Mirea.Api.Endpoint.Controllers.V1;
[ApiVersion("1.0")]
2024-08-24 02:27:05 +03:00
[CacheMaxAge(true)]
2024-05-28 07:09:40 +03:00
public class FacultyController(IMediator mediator) : BaseController
2024-02-16 23:57:05 +03:00
{
2024-05-28 07:09:40 +03:00
/// <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)
2024-02-16 23:57:05 +03:00
{
2024-05-28 07:09:40 +03:00
var result = await mediator.Send(new GetFacultyListQuery()
2024-02-16 23:57:05 +03:00
{
2024-05-28 07:09:40 +03:00
Page = page,
PageSize = pageSize
});
2024-02-16 23:57:05 +03:00
2024-05-28 07:09:40 +03:00
return Ok(result.Faculties
.Select(f => new FacultyResponse()
{
Id = f.Id,
2024-10-27 06:50:47 +03:00
Name = f.Name
2024-05-28 07:09:40 +03:00
})
);
}
}