2024-02-16 23:57:22 +03:00
|
|
|
|
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;
|
|
|
|
|
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
public class ProfessorController(IMediator mediator) : BaseController
|
2024-02-16 23:57:22 +03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves a list of professors.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page">The page number for pagination (optional).</param>
|
|
|
|
|
/// <param name="pageSize">The page size for pagination (optional).</param>
|
|
|
|
|
/// <returns>A list of professors.</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[BadRequestResponse]
|
|
|
|
|
public async Task<ActionResult<List<ProfessorResponse>>> 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
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves detailed information about a specific professor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">The ID of the professor to retrieve.</param>
|
|
|
|
|
/// <returns>Detailed information about the professor.</returns>
|
|
|
|
|
[HttpGet("{id:int}")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[BadRequestResponse]
|
|
|
|
|
[NotFoundResponse]
|
|
|
|
|
public async Task<ActionResult<ProfessorResponse>> 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
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|