From 88b4eb594ec7ef53e25547c0d6b7aa0c087d7469 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 28 Jan 2024 06:05:27 +0300 Subject: [PATCH] feat: add a controller for discipline --- .../Controllers/V1/DisciplineController.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Endpoint/Controllers/V1/DisciplineController.cs diff --git a/Endpoint/Controllers/V1/DisciplineController.cs b/Endpoint/Controllers/V1/DisciplineController.cs new file mode 100644 index 0000000..6589d31 --- /dev/null +++ b/Endpoint/Controllers/V1/DisciplineController.cs @@ -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 + { + /// + /// Gets a paginated list of disciplines. + /// + /// Page number. Start from 0. + /// Number of items per page. + /// Paginated list of disciplines. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + public async Task> Get([FromQuery] int? page, [FromQuery] int? pageSize) + { + var result = await mediator.Send(new GetDisciplineListQuery() + { + Page = page, + PageSize = pageSize + }); + + return Ok(result); + } + + /// + /// Gets details of a specific discipline by ID. + /// + /// Discipline ID. + /// Details of the specified discipline. + /// + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> GetDetails(int id) + { + var result = await mediator.Send(new GetDisciplineInfoQuery() + { + Id = id + }); + + return Ok(result); + } + } +}