Compare commits

..

No commits in common. "2ccc476686daf8a191daf32216015ad9d9100f83" and "f5dbc4685626324552f2e43b38af9d0fdcee8e3a" have entirely different histories.

8 changed files with 5 additions and 120 deletions

View File

@ -2,7 +2,6 @@
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;
@ -64,35 +63,4 @@ 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
}));
}
}

View File

@ -21,18 +21,10 @@ 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();

View File

@ -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}\".") { }
public NotFoundException(MemberInfo entity, object id) : base($"The entity \"{entity.Name}\" was not found by \"{id}\".") { }
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}\".") { }
}

View File

@ -2,16 +2,7 @@
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; }
}

View File

@ -11,13 +11,12 @@ public class GetProfessorInfoQueryHandler(IProfessorDbContext dbContext) : IRequ
{
public async Task<ProfessorInfoVm> Handle(GetProfessorInfoQuery request, CancellationToken cancellationToken)
{
var professor = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id);
var discipline = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id);
return new ProfessorInfoVm()
{
Id = professor.Id,
Name = professor.Name,
AltName = professor.AltName
Id = discipline.Id,
Name = discipline.Name,
};
}
}

View File

@ -1,17 +0,0 @@
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; }
}

View File

@ -1,33 +0,0 @@
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()
};
}
}

View File

@ -1,15 +0,0 @@
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; }
}