Merge remote-tracking branch 'origin/release/v1.0.0' into feat/controller-get
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 2m31s

This commit is contained in:
Polianin Nikita 2024-02-16 23:00:55 +03:00
commit 511c0db3ee
31 changed files with 560 additions and 10 deletions

View File

@ -1,5 +1,5 @@
using System.Reflection; using System;
using System; using System.Reflection;
namespace Mirea.Api.DataAccess.Application.Common.Exceptions; namespace Mirea.Api.DataAccess.Application.Common.Exceptions;

View File

@ -1,5 +1,4 @@
using MediatR; using MediatR;
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails; namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;

View File

@ -1,12 +1,9 @@
using System.Globalization; using MediatR;
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 Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions; 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; namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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>();
}

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View 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>();
}

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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>();
}

View File

@ -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; }
}

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.Professor), 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; }
}

View File

@ -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; }
}

View File

@ -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
};
}
}

View File

@ -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>();
}

View File

@ -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; }
}