feat: add search professors by name
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetailsBySearch;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
|
||||
using Mirea.Api.Dto.Responses;
|
||||
using Mirea.Api.Endpoint.Common.Attributes;
|
||||
@ -63,4 +64,35 @@ public class ProfessorController(IMediator mediator) : BaseController
|
||||
AltName = result.AltName
|
||||
});
|
||||
}
|
||||
|
||||
/// <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
|
||||
}));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user