Add controllers for the Get method #9
53
Endpoint/Controllers/V1/DisciplineController.cs
Normal file
53
Endpoint/Controllers/V1/DisciplineController.cs
Normal file
@ -0,0 +1,53 @@
|
||||
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.Endpoint.Common.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Controllers.V1
|
||||
{
|
||||
public class DisciplineController(IMediator mediator) : BaseControllerV1
|
||||
{
|
||||
/// <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<DisciplineListVm>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
|
||||
{
|
||||
var result = await mediator.Send(new GetDisciplineListQuery()
|
||||
{
|
||||
Page = page,
|
||||
PageSize = pageSize
|
||||
});
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <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<DisciplineInfoVm>> GetDetails(int id)
|
||||
{
|
||||
var result = await mediator.Send(new GetDisciplineInfoQuery()
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user