From f25c815506e9af00b5ecc2ff031e929b7f4957d3 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 28 Jan 2024 04:30:25 +0300 Subject: [PATCH 1/9] feat: add a not found exception --- Application/Common/Exceptions/NotFoundException.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Application/Common/Exceptions/NotFoundException.cs diff --git a/Application/Common/Exceptions/NotFoundException.cs b/Application/Common/Exceptions/NotFoundException.cs new file mode 100644 index 0000000..7cacf74 --- /dev/null +++ b/Application/Common/Exceptions/NotFoundException.cs @@ -0,0 +1,10 @@ +using System.Reflection; +using System; + +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}\".") { } +} \ No newline at end of file From bc99007d9487a614a97d5c99d52fa3d76f1437b8 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 28 Jan 2024 04:31:18 +0300 Subject: [PATCH 2/9] feat: add queries for the campus --- .../CampusBasicInfoDto.cs | 22 +++++++++++++++ .../CampusBasicInfoVm.cs | 14 ++++++++++ .../GetCampusBasicInfoListQuery.cs | 5 ++++ .../GetCampusBasicInfoListQueryHandler.cs | 26 ++++++++++++++++++ .../GetCampusDetails/CampusDetailsVm.cs | 27 +++++++++++++++++++ .../GetCampusDetails/GetCampusDetailsQuery.cs | 9 +++++++ .../GetCampusDetailsQueryHandler.cs | 27 +++++++++++++++++++ 7 files changed, 130 insertions(+) create mode 100644 Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs create mode 100644 Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs new file mode 100644 index 0000000..e0c9918 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +/// +/// Represents basic information about a campus. +/// +public class CampusBasicInfoDto +{ + /// + /// The unique identifier for the campus. + /// + public int Id { get; set; } + + /// + /// The code name associated with the campus. + /// + public required string CodeName { get; set; } + + /// + /// The full name of the campus. + /// + public string? FullName { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs new file mode 100644 index 0000000..a3a5f2d --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/CampusBasicInfoVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +/// +/// Represents a view model containing basic information about multiple campuses. +/// +public class CampusBasicInfoVm +{ + /// + /// The list of campus basic information. + /// + public IList Campuses { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs new file mode 100644 index 0000000..2059735 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQuery.cs @@ -0,0 +1,5 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +public class GetCampusBasicInfoListQuery : IRequest; \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs new file mode 100644 index 0000000..3cd6259 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusBasicInfoList/GetCampusBasicInfoListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs new file mode 100644 index 0000000..35246c1 --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/CampusDetailsVm.cs @@ -0,0 +1,27 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; + +/// +/// Represents a view model containing detailed information about a campus. +/// +public class CampusDetailsVm +{ + /// + /// The unique identifier for the campus. + /// + public int Id { get; set; } + + /// + /// The code name associated with the campus. + /// + public required string CodeName { get; set; } + + /// + /// The full name of the campus. + /// + public string? FullName { get; set; } + + /// + /// The address of the campus. + /// + public string? Address { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs new file mode 100644 index 0000000..f64bf8b --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs @@ -0,0 +1,9 @@ +using MediatR; +using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; + +public class GetCampusDetailsQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs new file mode 100644 index 0000000..2cb791c --- /dev/null +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs @@ -0,0 +1,27 @@ +using System.Globalization; +using System.Linq; +using MediatR; +using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; +using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; +using System.Threading.Tasks; +using System.Threading; +using Microsoft.EntityFrameworkCore; +using Mirea.Api.DataAccess.Application.Common.Exceptions; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; + +public class GetCampusDetailsQueryHandler(ICampusDbContext dbContext) : IRequestHandler +{ + public async Task 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 + }; + } +} \ No newline at end of file From a1a83ce2e6cf398922891e700c0df72312454e10 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 28 Jan 2024 05:59:48 +0300 Subject: [PATCH 3/9] feat: add queries for the discipline --- .../GetDisciplineDetails/DisciplineInfoVm.cs | 17 +++++++++++ .../GetDisciplineInfoQuery.cs | 8 +++++ .../GetDisciplineInfoQueryHandler.cs | 22 ++++++++++++++ .../GetDisciplineList/DisciplineListVm.cs | 14 +++++++++ .../GetDisciplineList/DisciplineLookupDto.cs | 17 +++++++++++ .../GetDisciplineListQuery.cs | 9 ++++++ .../GetDisciplineListQueryHandler.cs | 30 +++++++++++++++++++ 7 files changed, 117 insertions(+) create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineDetails/DisciplineInfoVm.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQuery.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQueryHandler.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineListVm.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineLookupDto.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQuery.cs create mode 100644 Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQueryHandler.cs diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/DisciplineInfoVm.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/DisciplineInfoVm.cs new file mode 100644 index 0000000..c6ac1b1 --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/DisciplineInfoVm.cs @@ -0,0 +1,17 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails; + +/// +/// Represents disciplines. +/// +public class DisciplineInfoVm +{ + /// + /// The unique identifier for the discipline. + /// + public int Id { get; set; } + + /// + /// The name of the discipline. + /// + public required string Name { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQuery.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQuery.cs new file mode 100644 index 0000000..b6c0621 --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails; + +public class GetDisciplineInfoQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQueryHandler.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQueryHandler.cs new file mode 100644 index 0000000..007e74f --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineDetails/GetDisciplineInfoQueryHandler.cs @@ -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 +{ + public async Task 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, + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineListVm.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineListVm.cs new file mode 100644 index 0000000..3f5c835 --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineListVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList; + +/// +/// Represents a view model containing multiple disciplines name. +/// +public class DisciplineListVm +{ + /// + /// The list of disciplines. + /// + public IList Disciplines { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineLookupDto.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineLookupDto.cs new file mode 100644 index 0000000..0a090df --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineList/DisciplineLookupDto.cs @@ -0,0 +1,17 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList; + +/// +/// Represents disciplines. +/// +public class DisciplineLookupDto +{ + /// + /// The unique identifier for the discipline. + /// + public int Id { get; set; } + + /// + /// The name of the discipline. + /// + public required string Name { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQuery.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQuery.cs new file mode 100644 index 0000000..f3b770b --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQuery.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList; + +public class GetDisciplineListQuery : IRequest +{ + public int? Page { get; set; } + public int? PageSize { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQueryHandler.cs b/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQueryHandler.cs new file mode 100644 index 0000000..c76ead2 --- /dev/null +++ b/Application/Cqrs/Discipline/Queries/GetDisciplineList/GetDisciplineListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file From c8c9b7f4560994f2f6129211674b8d2729ddaba9 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 18:06:22 +0300 Subject: [PATCH 4/9] feat: add queries for professor --- .../GetProfessorInfoQuery.cs | 8 +++++ .../GetProfessorInfoQueryHandler.cs | 22 +++++++++++++ .../GetProfessorDetails/ProfessorInfoVm.cs | 22 +++++++++++++ .../GetProfessorList/GetProfessorListQuery.cs | 9 ++++++ .../GetProfessorListQueryHandler.cs | 31 +++++++++++++++++++ .../GetProfessorList/ProfessorListVm.cs | 14 +++++++++ .../GetProfessorList/ProfessorLookupDto.cs | 22 +++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQuery.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorDetails/ProfessorInfoVm.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQuery.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQueryHandler.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorListVm.cs create mode 100644 Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorLookupDto.cs diff --git a/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQuery.cs b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQuery.cs new file mode 100644 index 0000000..93f1aa8 --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails; + +public class GetProfessorInfoQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs new file mode 100644 index 0000000..411a68d --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs @@ -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 +{ + public async Task 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, + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorDetails/ProfessorInfoVm.cs b/Application/Cqrs/Professor/Queries/GetProfessorDetails/ProfessorInfoVm.cs new file mode 100644 index 0000000..691ef9b --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorDetails/ProfessorInfoVm.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails; + +/// +/// Represents professors. +/// +public class ProfessorInfoVm +{ + /// + /// The unique identifier for the professor. + /// + public int Id { get; set; } + + /// + /// The name of the professor. + /// + public required string Name { get; set; } + + /// + /// The alt name of the professor. Usually is full name. + /// + public string? AltName { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQuery.cs b/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQuery.cs new file mode 100644 index 0000000..1a2e14b --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQuery.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList; + +public class GetProfessorListQuery : IRequest +{ + public int? Page { get; set; } + public int? PageSize { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQueryHandler.cs b/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQueryHandler.cs new file mode 100644 index 0000000..adcff57 --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorList/GetProfessorListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorListVm.cs b/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorListVm.cs new file mode 100644 index 0000000..f3bf0f2 --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorListVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList; + +/// +/// Represents a view model containing multiple professors name. +/// +public class ProfessorListVm +{ + /// + /// The list of professors. + /// + public IList Professors { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorLookupDto.cs b/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorLookupDto.cs new file mode 100644 index 0000000..4e32f26 --- /dev/null +++ b/Application/Cqrs/Professor/Queries/GetProfessorList/ProfessorLookupDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList; + +/// +/// Represents professor. +/// +public class ProfessorLookupDto +{ + /// + /// The unique identifier for the professor. + /// + public int Id { get; set; } + + /// + /// The name of the professor. + /// + public required string Name { get; set; } + + /// + /// The alt name of the professor. Usually is full name. + /// + public string? AltName { get; set; } +} \ No newline at end of file From 70c9a6347ec45e6f7ef99ffd9da2c477096cdca4 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 22:34:41 +0300 Subject: [PATCH 5/9] feat: add queries for group --- .../GetGroupDetails/GetGroupInfoQuery.cs | 8 +++++ .../GetGroupInfoQueryHandler.cs | 28 +++++++++++++++++ .../Queries/GetGroupDetails/GroupInfoVm.cs | 27 ++++++++++++++++ .../Queries/GetGroupList/GetGroupListQuery.cs | 9 ++++++ .../GetGroupList/GetGroupListQueryHandler.cs | 31 +++++++++++++++++++ .../Group/Queries/GetGroupList/GroupListVm.cs | 14 +++++++++ .../Queries/GetGroupList/GroupLookupDto.cs | 22 +++++++++++++ 7 files changed, 139 insertions(+) create mode 100644 Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQuery.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQueryHandler.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupDetails/GroupInfoVm.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQuery.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQueryHandler.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs create mode 100644 Application/Cqrs/Group/Queries/GetGroupList/GroupLookupDto.cs diff --git a/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQuery.cs b/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQuery.cs new file mode 100644 index 0000000..de0b87f --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails; + +public class GetGroupInfoQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQueryHandler.cs b/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQueryHandler.cs new file mode 100644 index 0000000..4d1a092 --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupDetails/GetGroupInfoQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupDetails/GroupInfoVm.cs b/Application/Cqrs/Group/Queries/GetGroupDetails/GroupInfoVm.cs new file mode 100644 index 0000000..8a4999c --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupDetails/GroupInfoVm.cs @@ -0,0 +1,27 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails; + +/// +/// Represents groups. +/// +public class GroupInfoVm +{ + /// + /// The unique identifier for the group. + /// + public int Id { get; set; } + + /// + /// The name of the group. + /// + public required string Name { get; set; } + + /// + /// The faculty name for the group. + /// + public string? Faculty { get; set; } + + /// + /// The faculty identifier for the group. + /// + public int? FacultyId { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQuery.cs b/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQuery.cs new file mode 100644 index 0000000..7bcc6c9 --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQuery.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList; + +public class GetGroupListQuery : IRequest +{ + public int? Page { get; set; } + public int? PageSize { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQueryHandler.cs b/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQueryHandler.cs new file mode 100644 index 0000000..b0d63b1 --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupList/GetGroupListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs b/Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs new file mode 100644 index 0000000..f4a777c --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupList/GroupListVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList; + +/// +/// Represents a view model containing multiple groups name. +/// +public class GroupListVm +{ + /// + /// The list of groups. + /// + public IList Groups { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Group/Queries/GetGroupList/GroupLookupDto.cs b/Application/Cqrs/Group/Queries/GetGroupList/GroupLookupDto.cs new file mode 100644 index 0000000..306f8d2 --- /dev/null +++ b/Application/Cqrs/Group/Queries/GetGroupList/GroupLookupDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList; + +/// +/// Represents groups. +/// +public class GroupLookupDto +{ + /// + /// The unique identifier for the group. + /// + public int Id { get; set; } + + /// + /// The name of the group. + /// + public required string Name { get; set; } + + /// + /// The faculty identifier for the group. + /// + public int? FacultyId { get; set; } +} \ No newline at end of file From 69a554ce762a377a10857980ea965ac30c2479bb Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 22:35:15 +0300 Subject: [PATCH 6/9] fix: change entity --- .../Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs index 411a68d..868201d 100644 --- a/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs +++ b/Application/Cqrs/Professor/Queries/GetProfessorDetails/GetProfessorInfoQueryHandler.cs @@ -11,7 +11,7 @@ public class GetProfessorInfoQueryHandler(IProfessorDbContext dbContext) : IRequ { public async Task 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); + var discipline = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id); return new ProfessorInfoVm() { From ce3bd2367379d98e8c329eb0185a9f68bb82679a Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 22:40:21 +0300 Subject: [PATCH 7/9] feat: add queries for faculty --- .../GetFacultyDetails/FacultyInfoVm.cs | 32 +++++++++++++++++++ .../GetFacultyDetails/GetFacultyInfoQuery.cs | 8 +++++ .../GetFacultyInfoQueryHandler.cs | 27 ++++++++++++++++ .../Queries/GetFacultyList/FacultyListVm.cs | 14 ++++++++ .../GetFacultyList/FacultyLookupDto.cs | 22 +++++++++++++ .../GetFacultyList/GetFacultyListQuery.cs | 9 ++++++ .../GetFacultyListQueryHandler.cs | 31 ++++++++++++++++++ 7 files changed, 143 insertions(+) create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyDetails/FacultyInfoVm.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQuery.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQueryHandler.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyListVm.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyLookupDto.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQuery.cs create mode 100644 Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQueryHandler.cs diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyDetails/FacultyInfoVm.cs b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/FacultyInfoVm.cs new file mode 100644 index 0000000..f7fb805 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/FacultyInfoVm.cs @@ -0,0 +1,32 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails; + +/// +/// Represents faculties. +/// +public class FacultyInfoVm +{ + /// + /// The unique identifier for the faculty. + /// + public int Id { get; set; } + + /// + /// The name of the faculty. + /// + public required string Name { get; set; } + + /// + /// ID indicating the faculty's affiliation to the campus. + /// + public int? CampusId { get; set; } + + /// + /// Campus name indicating the faculty's affiliation to the campus. + /// + public string? CampusName { get; set; } + + /// + /// Campus code indicating the faculty's affiliation to the campus. + /// + public string? CampusCode { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQuery.cs b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQuery.cs new file mode 100644 index 0000000..2517b14 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails; + +public class GetFacultyInfoQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQueryHandler.cs b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQueryHandler.cs new file mode 100644 index 0000000..a2f6486 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyDetails/GetFacultyInfoQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyListVm.cs b/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyListVm.cs new file mode 100644 index 0000000..8ad7d4b --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyListVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList; + +/// +/// Represents a view model containing multiple faculties. +/// +public class FacultyListVm +{ + /// + /// The list of faculties. + /// + public IList Faculties { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyLookupDto.cs b/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyLookupDto.cs new file mode 100644 index 0000000..7a8c615 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyList/FacultyLookupDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList; + +/// +/// Represents faculties. +/// +public class FacultyLookupDto +{ + /// + /// The unique identifier for the faculty. + /// + public int Id { get; set; } + + /// + /// The name of the faculty. + /// + public required string Name { get; set; } + + /// + /// ID indicating the faculty's affiliation to the campus. + /// + public int? CampusId { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQuery.cs b/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQuery.cs new file mode 100644 index 0000000..9abe675 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQuery.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList; + +public class GetFacultyListQuery : IRequest +{ + public int? Page { get; set; } + public int? PageSize { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQueryHandler.cs b/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQueryHandler.cs new file mode 100644 index 0000000..1249fe7 --- /dev/null +++ b/Application/Cqrs/Faculty/Queries/GetFacultyList/GetFacultyListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file From a00dc8ccd6fc1db6ab84fc4ab3b22d02eb2a4f37 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 22:51:26 +0300 Subject: [PATCH 8/9] feat: add queries for lecture hall --- .../GetLectureHallInfoQuery.cs | 8 +++++ .../GetLectureHallInfoQueryHandler.cs | 28 ++++++++++++++++ .../LectureHallInfoVm.cs | 32 +++++++++++++++++++ .../GetLectureHallListQuery.cs | 9 ++++++ .../GetLectureHallListQueryHandler.cs | 31 ++++++++++++++++++ .../GetLectureHallList/LectureHallListVm.cs | 14 ++++++++ .../LectureHallLookupDto.cs | 22 +++++++++++++ 7 files changed, 144 insertions(+) create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQuery.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQueryHandler.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/LectureHallInfoVm.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQuery.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQueryHandler.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallListVm.cs create mode 100644 Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallLookupDto.cs diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQuery.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQuery.cs new file mode 100644 index 0000000..284f218 --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQuery.cs @@ -0,0 +1,8 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails; + +public class GetLectureHallInfoQuery : IRequest +{ + public required int Id { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQueryHandler.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQueryHandler.cs new file mode 100644 index 0000000..17027a6 --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/GetLectureHallInfoQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/LectureHallInfoVm.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/LectureHallInfoVm.cs new file mode 100644 index 0000000..9b9c42f --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallDetails/LectureHallInfoVm.cs @@ -0,0 +1,32 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails; + +/// +/// Represents disciplines. +/// +public class LectureHallInfoVm +{ + /// + /// The unique identifier for the lecture hall. + /// + public int Id { get; set; } + + /// + /// The name of the lecture hall. + /// + public required string Name { get; set; } + + /// + /// ID indicating the lecture hall's affiliation to the campus. + /// + public int CampusId { get; set; } + + /// + /// Campus name indicating the lecture hall's affiliation to the campus. + /// + public string? CampusName { get; set; } + + /// + /// Campus code indicating the lecture hall's affiliation to the campus. + /// + public string? CampusCode { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQuery.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQuery.cs new file mode 100644 index 0000000..cb8ea83 --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQuery.cs @@ -0,0 +1,9 @@ +using MediatR; + +namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList; + +public class GetLectureHallListQuery : IRequest +{ + public int? Page { get; set; } + public int? PageSize { get; set; } +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQueryHandler.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQueryHandler.cs new file mode 100644 index 0000000..ac7b041 --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/GetLectureHallListQueryHandler.cs @@ -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 +{ + public async Task 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 + }; + } +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallListVm.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallListVm.cs new file mode 100644 index 0000000..8338f99 --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallListVm.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList; + +/// +/// Represents a view model containing multiple disciplines name. +/// +public class LectureHallListVm +{ + /// + /// The list of lecture hall. + /// + public IList LectureHalls { get; set; } = new List(); +} \ No newline at end of file diff --git a/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallLookupDto.cs b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallLookupDto.cs new file mode 100644 index 0000000..f00083c --- /dev/null +++ b/Application/Cqrs/LectureHall/Queries/GetLectureHallList/LectureHallLookupDto.cs @@ -0,0 +1,22 @@ +namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList; + +/// +/// Represents lecture halls. +/// +public class LectureHallLookupDto +{ + /// + /// The unique identifier for the lecture hall. + /// + public int Id { get; set; } + + /// + /// The name of the lecture hall. + /// + public required string Name { get; set; } + + /// + /// ID indicating the lecture hall's affiliation to the campus. + /// + public int CampusId { get; set; } +} \ No newline at end of file From ed823570f1b070d9a93a924fec1f901b48181fda Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 16 Feb 2024 22:52:36 +0300 Subject: [PATCH 9/9] refactor: code small --- Application/Common/Exceptions/NotFoundException.cs | 4 ++-- .../Queries/GetCampusDetails/GetCampusDetailsQuery.cs | 1 - .../GetCampusDetails/GetCampusDetailsQueryHandler.cs | 11 ++++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Application/Common/Exceptions/NotFoundException.cs b/Application/Common/Exceptions/NotFoundException.cs index 7cacf74..c310b74 100644 --- a/Application/Common/Exceptions/NotFoundException.cs +++ b/Application/Common/Exceptions/NotFoundException.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System; +using System; +using System.Reflection; namespace Mirea.Api.DataAccess.Application.Common.Exceptions; diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs index f64bf8b..8609b18 100644 --- a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQuery.cs @@ -1,5 +1,4 @@ using MediatR; -using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; diff --git a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs index 2cb791c..75af510 100644 --- a/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs +++ b/Application/Cqrs/Campus/Queries/GetCampusDetails/GetCampusDetailsQueryHandler.cs @@ -1,12 +1,9 @@ -using System.Globalization; -using System.Linq; -using MediatR; -using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList; -using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; -using System.Threading.Tasks; -using System.Threading; +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;