Add queries #8
10
Application/Common/Exceptions/NotFoundException.cs
Normal file
10
Application/Common/Exceptions/NotFoundException.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
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}\".") { }
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents basic information about a campus.
|
||||
/// </summary>
|
||||
public class CampusBasicInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the campus.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The code name associated with the campus.
|
||||
/// </summary>
|
||||
public required string CodeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full name of the campus.
|
||||
/// </summary>
|
||||
public string? FullName { get; set; }
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing basic information about multiple campuses.
|
||||
/// </summary>
|
||||
public class CampusBasicInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of campus basic information.
|
||||
/// </summary>
|
||||
public IList<CampusBasicInfoDto> Campuses { get; set; } = new List<CampusBasicInfoDto>();
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
public class GetCampusBasicInfoListQuery : IRequest<CampusBasicInfoVm>;
|
@ -0,0 +1,26 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
|
||||
|
||||
public class GetCampusBasicInfoListQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusBasicInfoListQuery, CampusBasicInfoVm>
|
||||
{
|
||||
public async Task<CampusBasicInfoVm> Handle(GetCampusBasicInfoListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = await dbContext.Campuses.Select(c => new CampusBasicInfoDto()
|
||||
{
|
||||
Id = c.Id,
|
||||
CodeName = c.CodeName,
|
||||
FullName = c.FullName
|
||||
}).ToListAsync(cancellationToken);
|
||||
|
||||
return new CampusBasicInfoVm
|
||||
{
|
||||
Campuses = dtos
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing detailed information about a campus.
|
||||
/// </summary>
|
||||
public class CampusDetailsVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the campus.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The code name associated with the campus.
|
||||
/// </summary>
|
||||
public required string CodeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full name of the campus.
|
||||
/// </summary>
|
||||
public string? FullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The address of the campus.
|
||||
/// </summary>
|
||||
public string? Address { get; set; }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
|
||||
|
||||
public class GetCampusDetailsQuery : IRequest<CampusDetailsVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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.Campus.Queries.GetCampusDetails;
|
||||
|
||||
public class GetCampusDetailsQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusDetailsQuery, CampusDetailsVm>
|
||||
{
|
||||
public async Task<CampusDetailsVm> Handle(GetCampusDetailsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var campus = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), request.Id);
|
||||
|
||||
return new CampusDetailsVm()
|
||||
{
|
||||
Id = campus.Id,
|
||||
CodeName = campus.CodeName,
|
||||
FullName = campus.FullName,
|
||||
Address = campus.Address
|
||||
};
|
||||
}
|
||||
}
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple disciplines name.
|
||||
/// </summary>
|
||||
public class DisciplineListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of disciplines.
|
||||
/// </summary>
|
||||
public IList<DisciplineLookupDto> Disciplines { get; set; } = new List<DisciplineLookupDto>();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents disciplines.
|
||||
/// </summary>
|
||||
public class DisciplineLookupDto
|
||||
{
|
||||
/// <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,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
||||
|
||||
public class GetDisciplineListQuery : IRequest<DisciplineListVm>
|
||||
{
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
|
||||
|
||||
public class GetDisciplineListQueryHandler(IDisciplineDbContext dbContext) : IRequestHandler<GetDisciplineListQuery, DisciplineListVm>
|
||||
{
|
||||
public async Task<DisciplineListVm> Handle(GetDisciplineListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.Disciplines.OrderBy(d => d.Id).Select(d => new DisciplineLookupDto()
|
||||
{
|
||||
Id = d.Id,
|
||||
Name = d.Name,
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new DisciplineListVm
|
||||
{
|
||||
Disciplines = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents faculties.
|
||||
/// </summary>
|
||||
public class FacultyInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the faculty.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the faculty.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID indicating the faculty's affiliation to the campus.
|
||||
/// </summary>
|
||||
public int? CampusId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Campus name indicating the faculty's affiliation to the campus.
|
||||
/// </summary>
|
||||
public string? CampusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Campus code indicating the faculty's affiliation to the campus.
|
||||
/// </summary>
|
||||
public string? CampusCode { get; set; }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
|
||||
|
||||
public class GetFacultyInfoQuery : IRequest<FacultyInfoVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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.Faculty.Queries.GetFacultyDetails;
|
||||
|
||||
public class GetFacultyInfoQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyInfoQuery, FacultyInfoVm>
|
||||
{
|
||||
public async Task<FacultyInfoVm> Handle(GetFacultyInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var faculty = await dbContext.Faculties
|
||||
.Include(f => f.Campus)
|
||||
.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Faculty), request.Id);
|
||||
|
||||
return new FacultyInfoVm()
|
||||
{
|
||||
Id = faculty.Id,
|
||||
Name = faculty.Name,
|
||||
CampusId = faculty.CampusId,
|
||||
CampusName = faculty.Campus?.FullName,
|
||||
CampusCode = faculty.Campus?.CodeName
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple faculties.
|
||||
/// </summary>
|
||||
public class FacultyListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of faculties.
|
||||
/// </summary>
|
||||
public IList<FacultyLookupDto> Faculties { get; set; } = new List<FacultyLookupDto>();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents faculties.
|
||||
/// </summary>
|
||||
public class FacultyLookupDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the faculty.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the faculty.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID indicating the faculty's affiliation to the campus.
|
||||
/// </summary>
|
||||
public int? CampusId { get; set; }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
||||
|
||||
public class GetFacultyListQuery : IRequest<FacultyListVm>
|
||||
{
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
|
||||
|
||||
public class GetFacultyListQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyListQuery, FacultyListVm>
|
||||
{
|
||||
public async Task<FacultyListVm> Handle(GetFacultyListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.Faculties.OrderBy(f => f.Id).Select(f => new FacultyLookupDto()
|
||||
{
|
||||
Id = f.Id,
|
||||
Name = f.Name,
|
||||
CampusId = f.CampusId
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new FacultyListVm
|
||||
{
|
||||
Faculties = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
|
||||
|
||||
public class GetGroupInfoQuery : IRequest<GroupInfoVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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.Group
|
||||
.Queries.GetGroupDetails;
|
||||
|
||||
public class GetGroupInfoQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupInfoQuery, GroupInfoVm>
|
||||
{
|
||||
public async Task<GroupInfoVm> Handle(GetGroupInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var discipline = await dbContext.Groups
|
||||
.Include(g => g.Faculty)
|
||||
.FirstOrDefaultAsync(g => g.Id == request.Id, cancellationToken)
|
||||
?? throw new NotFoundException(typeof(Domain.Schedule.Group), request.Id);
|
||||
|
||||
return new GroupInfoVm()
|
||||
{
|
||||
Id = discipline.Id,
|
||||
Name = discipline.Name,
|
||||
Faculty = discipline.Faculty?.Name,
|
||||
FacultyId = discipline.FacultyId
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents groups.
|
||||
/// </summary>
|
||||
public class GroupInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the group.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the group.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The faculty name for the group.
|
||||
/// </summary>
|
||||
public string? Faculty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The faculty identifier for the group.
|
||||
/// </summary>
|
||||
public int? FacultyId { get; set; }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
|
||||
|
||||
public class GetGroupListQuery : IRequest<GroupListVm>
|
||||
{
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
|
||||
|
||||
public class GetGroupListQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupListQuery, GroupListVm>
|
||||
{
|
||||
public async Task<GroupListVm> Handle(GetGroupListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.Groups.OrderBy(g => g.Id).Select(g => new GroupLookupDto()
|
||||
{
|
||||
Id = g.Id,
|
||||
Name = g.Name,
|
||||
FacultyId = g.FacultyId
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new GroupListVm
|
||||
{
|
||||
Groups = result
|
||||
};
|
||||
}
|
||||
}
|
14
Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs
Normal file
14
Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple groups name.
|
||||
/// </summary>
|
||||
public class GroupListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of groups.
|
||||
/// </summary>
|
||||
public IList<GroupLookupDto> Groups { get; set; } = new List<GroupLookupDto>();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents groups.
|
||||
/// </summary>
|
||||
public class GroupLookupDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the group.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the group.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The faculty identifier for the group.
|
||||
/// </summary>
|
||||
public int? FacultyId { get; set; }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
|
||||
|
||||
public class GetLectureHallInfoQuery : IRequest<LectureHallInfoVm>
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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.LectureHall.Queries.GetLectureHallDetails;
|
||||
|
||||
public class GetLectureHallInfoQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallInfoQuery, LectureHallInfoVm>
|
||||
{
|
||||
public async Task<LectureHallInfoVm> Handle(GetLectureHallInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var lectureHall = await dbContext.LectureHalls
|
||||
.Include(l => l.Campus)
|
||||
.FirstOrDefaultAsync(l => l.Id == request.Id, cancellationToken)
|
||||
?? throw new NotFoundException(typeof(Domain.Schedule.LectureHall), request.Id);
|
||||
|
||||
return new LectureHallInfoVm()
|
||||
{
|
||||
Id = lectureHall.Id,
|
||||
Name = lectureHall.Name,
|
||||
CampusId = lectureHall.CampusId,
|
||||
CampusCode = lectureHall.Campus?.CodeName,
|
||||
CampusName = lectureHall.Campus?.FullName
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
|
||||
|
||||
/// <summary>
|
||||
/// Represents disciplines.
|
||||
/// </summary>
|
||||
public class LectureHallInfoVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the lecture hall.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the lecture hall.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID indicating the lecture hall's affiliation to the campus.
|
||||
/// </summary>
|
||||
public int CampusId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Campus name indicating the lecture hall's affiliation to the campus.
|
||||
/// </summary>
|
||||
public string? CampusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Campus code indicating the lecture hall's affiliation to the campus.
|
||||
/// </summary>
|
||||
public string? CampusCode { get; set; }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||
|
||||
public class GetLectureHallListQuery : IRequest<LectureHallListVm>
|
||||
{
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||
|
||||
public class GetLectureHallListQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallListQuery, LectureHallListVm>
|
||||
{
|
||||
public async Task<LectureHallListVm> Handle(GetLectureHallListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.LectureHalls.OrderBy(l => l.Id).Select(l => new LectureHallLookupDto()
|
||||
{
|
||||
Id = l.Id,
|
||||
Name = l.Name,
|
||||
CampusId = l.CampusId
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new LectureHallListVm
|
||||
{
|
||||
LectureHalls = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple disciplines name.
|
||||
/// </summary>
|
||||
public class LectureHallListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of lecture hall.
|
||||
/// </summary>
|
||||
public IList<LectureHallLookupDto> LectureHalls { get; set; } = new List<LectureHallLookupDto>();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents lecture halls.
|
||||
/// </summary>
|
||||
public class LectureHallLookupDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for the lecture hall.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the lecture hall.
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID indicating the lecture hall's affiliation to the campus.
|
||||
/// </summary>
|
||||
public int CampusId { get; set; }
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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.Professor), request.Id);
|
||||
|
||||
return new ProfessorInfoVm()
|
||||
{
|
||||
Id = discipline.Id,
|
||||
Name = discipline.Name,
|
||||
};
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
|
||||
|
||||
public class GetProfessorListQuery : IRequest<ProfessorListVm>
|
||||
{
|
||||
public int? Page { get; set; }
|
||||
public int? PageSize { get; set; }
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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.GetProfessorList;
|
||||
|
||||
public class GetProfessorListQueryHandler(IProfessorDbContext dbContext) : IRequestHandler<GetProfessorListQuery, ProfessorListVm>
|
||||
{
|
||||
public async Task<ProfessorListVm> Handle(GetProfessorListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var dtos = dbContext.Professors.OrderBy(p => p.Id).Select(p => new ProfessorLookupDto()
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
AltName = p.AltName
|
||||
});
|
||||
|
||||
if (request is { PageSize: not null, Page: not null })
|
||||
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
|
||||
|
||||
var result = await dtos.ToListAsync(cancellationToken);
|
||||
|
||||
return new ProfessorListVm
|
||||
{
|
||||
Professors = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model containing multiple professors name.
|
||||
/// </summary>
|
||||
public class ProfessorListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of professors.
|
||||
/// </summary>
|
||||
public IList<ProfessorLookupDto> Professors { get; set; } = new List<ProfessorLookupDto>();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents professor.
|
||||
/// </summary>
|
||||
public class ProfessorLookupDto
|
||||
{
|
||||
/// <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; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user