refactor: move database-related projects to separate folder

This commit is contained in:
2024-05-29 07:49:42 +03:00
parent 081c814036
commit bf3a9d4b36
74 changed files with 5 additions and 43 deletions

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