MireaBackend/Endpoint/Controllers/V1/DisciplineController.cs

65 lines
2.0 KiB
C#
Raw Normal View History

2024-01-28 06:05:27 +03:00
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
2024-01-28 06:05:27 +03:00
using System.Threading.Tasks;
2024-05-28 07:09:40 +03:00
namespace Mirea.Api.Endpoint.Controllers.V1;
[ApiVersion("1.0")]
public class DisciplineController(IMediator mediator) : BaseController
2024-01-28 06:05:27 +03:00
{
2024-05-28 07:09:40 +03:00
/// <summary>
/// Gets a paginated list of disciplines.
/// </summary>
/// <param name="page">Page number. Start from 0.</param>
/// <param name="pageSize">Number of items per page.</param>
/// <returns>Paginated list of disciplines.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
public async Task<ActionResult<List<DisciplineResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
2024-01-28 06:05:27 +03:00
{
2024-05-28 07:09:40 +03:00
var result = await mediator.Send(new GetDisciplineListQuery()
2024-01-28 06:05:27 +03:00
{
2024-05-28 07:09:40 +03:00
Page = page,
PageSize = pageSize
});
2024-01-28 06:05:27 +03:00
2024-05-28 07:09:40 +03:00
return Ok(result.Disciplines
.Select(d => new DisciplineResponse()
{
Id = d.Id,
Name = d.Name
})
);
}
2024-01-28 06:05:27 +03:00
2024-05-28 07:09:40 +03:00
/// <summary>
/// Gets details of a specific discipline by ID.
/// </summary>
/// <param name="id">Discipline ID.</param>
/// <returns>Details of the specified discipline.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<DisciplineResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetDisciplineInfoQuery()
2024-01-28 06:05:27 +03:00
{
2024-05-28 07:09:40 +03:00
Id = id
});
2024-01-28 06:05:27 +03:00
2024-05-28 07:09:40 +03:00
return Ok(new DisciplineResponse()
{
Id = result.Id,
Name = result.Name
});
2024-01-28 06:05:27 +03:00
}
2024-05-28 07:09:40 +03:00
}