using Asp.Versioning; using MediatR; 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; using System.Threading.Tasks; namespace Mirea.Api.Endpoint.Controllers.V1; [ApiVersion("1.0")] [CacheMaxAge(true)] public class DisciplineController(IMediator mediator) : BaseController { /// /// Gets a paginated list of disciplines. /// /// Page number. Start from 0. /// Number of items per page. /// Paginated list of disciplines. [HttpGet] [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.Disciplines .Select(d => new DisciplineResponse() { Id = d.Id, Name = d.Name }) ); } /// /// Gets details of a specific discipline by ID. /// /// Discipline ID. /// Details of the specified discipline. [HttpGet("{id:int}")] [BadRequestResponse] [NotFoundResponse] public async Task> GetDetails(int id) { var result = await mediator.Send(new GetDisciplineInfoQuery() { Id = id }); return Ok(new DisciplineResponse() { Id = result.Id, Name = result.Name }); } }