From 5cfc07ab7d929b5c659e3f536b56d35dfb2a6773 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 23:57:22 +0300 Subject: [PATCH] feat: add controller for professor --- .../Controllers/V1/ProfessorController.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Endpoint/Controllers/V1/ProfessorController.cs diff --git a/Endpoint/Controllers/V1/ProfessorController.cs b/Endpoint/Controllers/V1/ProfessorController.cs new file mode 100644 index 0000000..5a9053a --- /dev/null +++ b/Endpoint/Controllers/V1/ProfessorController.cs @@ -0,0 +1,66 @@ +using MediatR; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails; +using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList; +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; + +public class ProfessorController(IMediator mediator) : BaseControllerV1 +{ + /// + /// Retrieves a list of professors. + /// + /// The page number for pagination (optional). + /// The page size for pagination (optional). + /// A list of professors. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + public async Task>> Get([FromQuery] int? page, [FromQuery] int? pageSize) + { + var result = await mediator.Send(new GetProfessorListQuery() + { + Page = page, + PageSize = pageSize + }); + + return Ok(result.Professors + .Select(p => new ProfessorResponse() + { + Id = p.Id, + Name = p.Name, + AltName = p.AltName + }) + ); + } + + /// + /// Retrieves detailed information about a specific professor. + /// + /// The ID of the professor to retrieve. + /// Detailed information about the professor. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> GetDetails(int id) + { + var result = await mediator.Send(new GetProfessorInfoQuery() + { + Id = id + }); + + return Ok(new ProfessorResponse() + { + Id = result.Id, + Name = result.Name, + AltName = result.AltName + }); + } +} \ No newline at end of file