feat: add queries for professor
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m44s

This commit is contained in:
2024-02-16 18:06:22 +03:00
parent a1a83ce2e6
commit c8c9b7f456
7 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
public class GetProfessorInfoQuery : IRequest<ProfessorInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,22 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
public class GetProfessorInfoQueryHandler(IProfessorDbContext dbContext) : IRequestHandler<GetProfessorInfoQuery, ProfessorInfoVm>
{
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.Group), request.Id);
return new ProfessorInfoVm()
{
Id = discipline.Id,
Name = discipline.Name,
};
}
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
/// <summary>
/// Represents professors.
/// </summary>
public class ProfessorInfoVm
{
/// <summary>
/// The unique identifier for the professor.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the professor.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// The alt name of the professor. Usually is full name.
/// </summary>
public string? AltName { get; set; }
}