feat: add queries for the discipline
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m28s
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m28s
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents disciplines.
|
||||
/// </summary>
|
||||
public class DisciplineInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the discipline.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the discipline.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
|
||||
|
||||
public class GetDisciplineInfoQuery : IRequest<DisciplineInfoVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -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.Discipline.Queries.GetDisciplineDetails;
|
||||
|
||||
public class GetDisciplineInfoQueryHandler(IDisciplineDbContext dbContext) : IRequestHandler<GetDisciplineInfoQuery, DisciplineInfoVm>
|
||||
{
|
||||
public async Task<DisciplineInfoVm> Handle(GetDisciplineInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var discipline = await dbContext.Disciplines.FirstOrDefaultAsync(d => d.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Discipline), request.Id);
|
||||
|
||||
return new DisciplineInfoVm()
|
||||
{
|
||||
Id = discipline.Id,
|
||||
Name = discipline.Name,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user