2024-09-18 06:00:07 +03:00
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
using MediatR;
|
2024-02-16 23:57:22 +03:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
|
2024-10-25 04:44:18 +03:00
|
|
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetailsBySearch;
|
2024-02-16 23:57:22 +03:00
|
|
|
|
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")]
|
2024-08-24 02:27:05 +03:00
|
|
|
|
[CacheMaxAge(true)]
|
2024-05-28 07:09:40 +03:00
|
|
|
|
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]
|
|
|
|
|
[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}")]
|
|
|
|
|
[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
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-25 04:44:18 +03:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves detailed information about professors based on their name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method searches for professors whose name matches the provided search term.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="name">The name of the professor to search for. Must be at least 4 characters long.</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A list of <see cref="ProfessorResponse"/> objects containing the details of the matching professors.
|
|
|
|
|
/// </returns>
|
|
|
|
|
[HttpGet("{name:required}")]
|
|
|
|
|
[BadRequestResponse]
|
|
|
|
|
[NotFoundResponse]
|
|
|
|
|
public async Task<ActionResult<List<ProfessorResponse>>> GetDetails(string name)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(name) || name.Length < 4)
|
|
|
|
|
return BadRequest($"The minimum number of characters is 4 (current: {name.Length}).");
|
|
|
|
|
|
|
|
|
|
var result = await mediator.Send(new GetProfessorInfoSearchQuery()
|
|
|
|
|
{
|
|
|
|
|
Name = name
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Ok(result.Details.Select(x => new ProfessorResponse()
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
AltName = x.AltName
|
|
|
|
|
}));
|
|
|
|
|
}
|
2024-02-16 23:57:22 +03:00
|
|
|
|
}
|