Compare commits
4 Commits
f5dbc46856
...
2ccc476686
Author | SHA1 | Date | |
---|---|---|---|
2ccc476686 | |||
84d7b095f0 | |||
4605c81895 | |||
0788c36bd2 |
@ -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
|
||||
}));
|
||||
}
|
||||
}
|
@ -21,10 +21,18 @@ namespace Mirea.Api.Endpoint.Controllers.V1;
|
||||
[CacheMaxAge(true)]
|
||||
public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConfig> config) : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the start term for the schedule.
|
||||
/// </summary>
|
||||
/// <returns>The start term as a <see cref="DateOnly"/> value.</returns>
|
||||
[CacheMaxAge(1, 0)]
|
||||
[HttpGet("StartTerm")]
|
||||
public ActionResult<DateOnly> GetStartTerm() => config.Value.ScheduleSettings!.StartTerm;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the pair periods.
|
||||
/// </summary>
|
||||
/// <returns>A dictionary of pair periods, where the key is an integer identifier and the value is a <see cref="PairPeriodTime"/> object.</returns>
|
||||
[CacheMaxAge(1, 0)]
|
||||
[HttpGet("PairPeriod")]
|
||||
public ActionResult<Dictionary<int, PairPeriodTime>> GetPairPeriod() => config.Value.ScheduleSettings!.PairPeriod.ConvertToDto();
|
||||
|
@ -5,6 +5,6 @@ namespace Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||
|
||||
public class NotFoundException : Exception
|
||||
{
|
||||
public NotFoundException(MemberInfo entity, string name, object id) : base($"The entity \"{entity.Name}\" property \"{name}\" was not found by id \"{id}\".") { }
|
||||
public NotFoundException(MemberInfo entity, object id) : base($"The entity \"{entity.Name}\" was not found by id \"{id}\".") { }
|
||||
public NotFoundException(MemberInfo entity, string name, object id) : base($"The entity \"{entity.Name}\" property \"{name}\" was not found by \"{id}\".") { }
|
||||
public NotFoundException(MemberInfo entity, object id) : base($"The entity \"{entity.Name}\" was not found by \"{id}\".") { }
|
||||
}
|
@ -2,7 +2,16 @@
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a query to retrieve information about a professor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This query can be used to fetch details of a professor by either their unique identifier.
|
||||
/// </remarks>
|
||||
public class GetProfessorInfoQuery : IRequest<ProfessorInfoVm>
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the professor.
|
||||
/// </summary>
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -11,12 +11,13 @@ public class GetProfessorInfoQueryHandler(IProfessorDbContext dbContext) : IRequ
|
||||
{
|
||||
public async Task<ProfessorInfoVm> Handle(GetProfessorInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var discipline = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id);
|
||||
var professor = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id);
|
||||
|
||||
return new ProfessorInfoVm()
|
||||
{
|
||||
Id = discipline.Id,
|
||||
Name = discipline.Name,
|
||||
Id = professor.Id,
|
||||
Name = professor.Name,
|
||||
AltName = professor.AltName
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetailsBySearch;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a query to retrieve information about a professor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This query can be used to fetch details of a professor by either their name.
|
||||
/// </remarks>
|
||||
public class GetProfessorInfoSearchQuery : IRequest<ProfessorInfoListVm>
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the professor.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetailsBySearch;
|
||||
|
||||
public class GetProfessorInfoSearchQueryHandler(IProfessorDbContext dbContext) : IRequestHandler<GetProfessorInfoSearchQuery, ProfessorInfoListVm>
|
||||
{
|
||||
public async Task<ProfessorInfoListVm> Handle(GetProfessorInfoSearchQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var name = request.Name.ToLower();
|
||||
var professor = await dbContext.Professors
|
||||
.Where(p => p.Name.ToLower().Contains(name) ||
|
||||
(p.AltName != null && p.AltName.ToLower().Contains(name)))
|
||||
.ToListAsync(cancellationToken)
|
||||
?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Name);
|
||||
|
||||
return new ProfessorInfoListVm()
|
||||
{
|
||||
Details = professor.Select(x => new ProfessorInfoVm()
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
AltName = x.AltName
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetailsBySearch;
|
||||
|
||||
/// <summary>
|
||||
/// Represents professors.
|
||||
/// </summary>
|
||||
public class ProfessorInfoListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// List of <see cref="ProfessorInfoVm"/>
|
||||
/// </summary>
|
||||
public required IList<ProfessorInfoVm> Details { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user