Compare commits
62 Commits
master
...
feat/appli
Author | SHA1 | Date | |
---|---|---|---|
467d37fc4e | |||
7a0a51f76a | |||
92504295f0 | |||
c5c4a2a8da | |||
806c3eeb17 | |||
3294325ad0 | |||
459d11dd6b | |||
2b02cfb616 | |||
98ebe5ffdb | |||
7b8bff8e54 | |||
f1ed45af96 | |||
d5b3859e86 | |||
788103c8a5 | |||
e6cc9437d5 | |||
8f334ae5c2 | |||
3c3bdc6155 | |||
e1c3165ad3 | |||
e6c62eae09 | |||
cea8a14f8b | |||
2c3e02b2de | |||
84c6123caf | |||
2d973eee3d | |||
66dc5e3e38 | |||
9493d4340f | |||
194dd1b729 | |||
e7c05b4a68 | |||
bd3a11486d | |||
28e862c670 | |||
9e4320f2d3 | |||
03ccec2119 | |||
96a120f017 | |||
2bb7573ca0 | |||
c82b29e90e | |||
6fde0003e0 | |||
4fe25005af | |||
b9b34a29e8 | |||
31c214d955 | |||
dbc8f7c68c | |||
654065f016 | |||
9b0e5a3f15 | |||
af7e370494 | |||
83f85ebb7b | |||
9aa74218aa | |||
67e9b89379 | |||
6f5a662e2f | |||
def7111651 | |||
b4bbc413f2 | |||
6f5a84f645 | |||
f9a04ee84a | |||
84214e38cc | |||
40279ab2b8 | |||
cb55567519 | |||
8e628d17da | |||
9e9d4e06fd | |||
cfbd847d9a | |||
386272d493 | |||
924f97332f | |||
a389eb0a70 | |||
8028d40005 | |||
f7998a1798 | |||
9f1c3cd648 | |||
4eecc19f4f |
26
.gitea/workflows/test.yaml
Normal file
26
.gitea/workflows/test.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: .NET Test Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [master, 'release/*']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up .NET Core
|
||||||
|
uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: 8.0.x
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore
|
||||||
|
|
||||||
|
- name: Build the solution
|
||||||
|
run: dotnet build --configuration Release
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: dotnet test --configuration Release --no-build --no-restore --verbosity normal
|
27
Application/Application.csproj
Normal file
27
Application/Application.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Company>Winsomnia</Company>
|
||||||
|
<Version>1.0.0-a0</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<AssemblyName>Mirea.Api.DataAccess.Application</AssemblyName>
|
||||||
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="11.9.0" />
|
||||||
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
|
||||||
|
<PackageReference Include="MediatR" Version="12.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
30
Application/Common/Behaviors/ValidationBehavior.cs
Normal file
30
Application/Common/Behaviors/ValidationBehavior.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using MediatR;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Common.Behaviors;
|
||||||
|
|
||||||
|
public class ValidationBehavior<TRequest, TResponse>(IEnumerable<IValidator<TRequest>> validators)
|
||||||
|
: IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
|
||||||
|
{
|
||||||
|
public Task<TResponse> Handle(TRequest request,
|
||||||
|
RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var context = new ValidationContext<TRequest>(request);
|
||||||
|
var failures = validators
|
||||||
|
.Select(v => v.Validate(context))
|
||||||
|
.SelectMany(result => result.Errors)
|
||||||
|
.Where(failure => failure != null)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (failures.Count != 0)
|
||||||
|
{
|
||||||
|
throw new ValidationException(failures);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
}
|
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}\".") { }
|
||||||
|
}
|
10
Application/Common/Exceptions/RecordExistException.cs
Normal file
10
Application/Common/Exceptions/RecordExistException.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||||
|
|
||||||
|
public class RecordExistException : Exception
|
||||||
|
{
|
||||||
|
public RecordExistException(MemberInfo entity, string name, object id) : base($"The entity \"{entity.Name}\" property \"{name}\" exists with id \"{id}\".") { }
|
||||||
|
public RecordExistException(MemberInfo entity, object id) : base($"The entity \"{entity.Name}\" exists with id \"{id}\".") { }
|
||||||
|
}
|
28
Application/Common/Mappings/AssemblyMappingProfile.cs
Normal file
28
Application/Common/Mappings/AssemblyMappingProfile.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Common.Mappings;
|
||||||
|
|
||||||
|
public class AssemblyMappingProfile : Profile
|
||||||
|
{
|
||||||
|
public AssemblyMappingProfile(Assembly assembly) =>
|
||||||
|
ApplyMappingsFromAssembly(assembly);
|
||||||
|
|
||||||
|
private void ApplyMappingsFromAssembly(Assembly assembly)
|
||||||
|
{
|
||||||
|
var types = assembly.GetExportedTypes()
|
||||||
|
.Where(type => type.GetInterfaces()
|
||||||
|
.Any(i => i.IsGenericType &&
|
||||||
|
i.GetGenericTypeDefinition() == typeof(IMapWith<>)))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var type in types)
|
||||||
|
{
|
||||||
|
var instance = Activator.CreateInstance(type);
|
||||||
|
var methodInfo = type.GetMethod("Mapping");
|
||||||
|
methodInfo?.Invoke(instance, new[] { this });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Application/Common/Mappings/IMapWith.cs
Normal file
9
Application/Common/Mappings/IMapWith.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Common.Mappings;
|
||||||
|
|
||||||
|
public interface IMapWith<T>
|
||||||
|
{
|
||||||
|
void Mapping(Profile profile) =>
|
||||||
|
profile.CreateMap(typeof(T), GetType());
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Commands.CreateCampus;
|
||||||
|
|
||||||
|
public class CreateCampusCommand : IRequest<int>
|
||||||
|
{
|
||||||
|
public required string CodeName { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
public string? Address { get; set; }
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
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.Commands.CreateCampus;
|
||||||
|
|
||||||
|
public class CreateCampusCommandHandler(ICampusDbContext dbContext) : IRequestHandler<CreateCampusCommand, int>
|
||||||
|
{
|
||||||
|
public async Task<int> Handle(CreateCampusCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Campuses.FirstOrDefaultAsync(c => c.CodeName == request.CodeName, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (entity != null)
|
||||||
|
throw new RecordExistException(typeof(Domain.Schedule.Campus), nameof(Domain.Schedule.Campus.CodeName), entity.Id);
|
||||||
|
|
||||||
|
var campus = new Domain.Schedule.Campus()
|
||||||
|
{
|
||||||
|
CodeName = request.CodeName,
|
||||||
|
FullName = request.FullName,
|
||||||
|
Address = request.Address
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await dbContext.Campuses.AddAsync(campus, cancellationToken);
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return result.Entity.Id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Commands.UpdateCampus;
|
||||||
|
|
||||||
|
public class UpdateCampusCommand : IRequest
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
public string? Address { get; set; }
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
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.Commands.UpdateCampus;
|
||||||
|
|
||||||
|
public class UpdateCampusCommandHandler(ICampusDbContext dbContext) : IRequestHandler<UpdateCampusCommand>
|
||||||
|
{
|
||||||
|
public async Task Handle(UpdateCampusCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), nameof(Domain.Schedule.Campus.Id), request.Id);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(request.FullName))
|
||||||
|
entity.FullName = request.FullName;
|
||||||
|
if (!string.IsNullOrEmpty(request.Address))
|
||||||
|
entity.Address = request.Address;
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Commands.CreateFaculty;
|
||||||
|
|
||||||
|
public class CreateFacultyCommand : IRequest<int>
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public int? CampusId { get; set; }
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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.Commands.CreateFaculty;
|
||||||
|
|
||||||
|
public class CreateFacultyCommandHandler(IFacultyDbContext dbContext) : IRequestHandler<CreateFacultyCommand, int>
|
||||||
|
{
|
||||||
|
public async Task<int> Handle(CreateFacultyCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Faculties.FirstOrDefaultAsync(f => f.Name == request.Name, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (entity != null)
|
||||||
|
throw new RecordExistException(typeof(Domain.Schedule.Faculty), nameof(Domain.Schedule.Faculty.Name), entity.Id);
|
||||||
|
|
||||||
|
var faculty = new Domain.Schedule.Faculty()
|
||||||
|
{
|
||||||
|
Name = request.Name,
|
||||||
|
CampusId = request.CampusId
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await dbContext.Faculties.AddAsync(faculty, cancellationToken);
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return result.Entity.Id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Commands.UpdateFaculty;
|
||||||
|
|
||||||
|
public class UpdateFacultyCommand : IRequest
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
public required int CampusId { get; set; }
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
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.Commands.UpdateFaculty;
|
||||||
|
|
||||||
|
public class UpdateFacultyCommandHandler(IFacultyDbContext dbContext) : IRequestHandler<UpdateFacultyCommand>
|
||||||
|
{
|
||||||
|
public async Task Handle(UpdateFacultyCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Faculties.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Faculty), nameof(Domain.Schedule.Faculty.Id), request.Id);
|
||||||
|
|
||||||
|
entity.CampusId = request.CampusId;
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Commands.CreateGroup;
|
||||||
|
|
||||||
|
public class CreateGroupCommand : IRequest<int>
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public int? FacultyId { get; set; }
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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.Commands.CreateGroup;
|
||||||
|
|
||||||
|
public class CreateGroupCommandHandler(IGroupDbContext dbContext) : IRequestHandler<CreateGroupCommand, int>
|
||||||
|
{
|
||||||
|
public async Task<int> Handle(CreateGroupCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Groups.FirstOrDefaultAsync(g => g.Name == request.Name, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (entity != null)
|
||||||
|
throw new RecordExistException(typeof(Domain.Schedule.Group), nameof(Domain.Schedule.Group.Name), entity.Id);
|
||||||
|
|
||||||
|
var group = new Domain.Schedule.Group()
|
||||||
|
{
|
||||||
|
Name = request.Name,
|
||||||
|
FacultyId = request.FacultyId
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await dbContext.Groups.AddAsync(group, cancellationToken);
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return result.Entity.Id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Commands.UpdateGroup;
|
||||||
|
|
||||||
|
public class UpdateGroupCommand : IRequest
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
public required int FacultyId { get; set; }
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
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.Commands.UpdateGroup;
|
||||||
|
|
||||||
|
public class UpdateGroupCommandHandler(IGroupDbContext dbContext) : IRequestHandler<UpdateGroupCommand>
|
||||||
|
{
|
||||||
|
public async Task Handle(UpdateGroupCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Groups.FirstOrDefaultAsync(g => g.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Group), nameof(Domain.Schedule.Group.Id), request.Id);
|
||||||
|
|
||||||
|
entity.FacultyId = request.FacultyId;
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.CreateProfessor;
|
||||||
|
|
||||||
|
public class CreateProfessorCommand : IRequest<int>
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public string? AltName { get; set; }
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.CreateProfessor;
|
||||||
|
|
||||||
|
public class CreateProfessorCommandHandler(IProfessorDbContext dbContext) : IRequestHandler<CreateProfessorCommand, int>
|
||||||
|
{
|
||||||
|
public async Task<int> Handle(CreateProfessorCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Professors.FirstOrDefaultAsync(p => p.Name == request.Name, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (entity != null)
|
||||||
|
throw new RecordExistException(typeof(Domain.Schedule.Professor), nameof(Domain.Schedule.Professor.Name), entity.Id);
|
||||||
|
|
||||||
|
var professor = new Domain.Schedule.Professor()
|
||||||
|
{
|
||||||
|
Name = request.Name,
|
||||||
|
AltName = request.AltName
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await dbContext.Professors.AddAsync(professor, cancellationToken);
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return result.Entity.Id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.UpdateProfessor;
|
||||||
|
|
||||||
|
public class UpdateProfessorCommand : IRequest
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
public required string AltName { get; set; }
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Commands.UpdateProfessor;
|
||||||
|
|
||||||
|
public class UpdateProfessorCommandHandler(IProfessorDbContext dbContext) : IRequestHandler<UpdateProfessorCommand>
|
||||||
|
{
|
||||||
|
public async Task Handle(UpdateProfessorCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), nameof(Domain.Schedule.Professor.Id), request.Id);
|
||||||
|
|
||||||
|
entity.AltName = request.AltName;
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Commands.CreateTypeOfOccupation;
|
||||||
|
|
||||||
|
public class CreateTypeOfOccupationCommand : IRequest<int>
|
||||||
|
{
|
||||||
|
public required string ShortName { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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.TypeOfOccupation.Commands.CreateTypeOfOccupation;
|
||||||
|
|
||||||
|
public class CreateTypeOfOccupationCommandHandler(ITypeOfOccupationDbContext dbContext) : IRequestHandler<CreateTypeOfOccupationCommand, int>
|
||||||
|
{
|
||||||
|
public async Task<int> Handle(CreateTypeOfOccupationCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.TypeOfOccupations.FirstOrDefaultAsync(t => t.ShortName == request.ShortName, cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
if (entity != null)
|
||||||
|
throw new RecordExistException(typeof(Domain.Schedule.TypeOfOccupation), nameof(Domain.Schedule.TypeOfOccupation.ShortName), entity.Id);
|
||||||
|
|
||||||
|
var typeOfOccupation = new Domain.Schedule.TypeOfOccupation
|
||||||
|
{
|
||||||
|
ShortName = request.ShortName,
|
||||||
|
FullName = request.FullName
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await dbContext.TypeOfOccupations.AddAsync(typeOfOccupation, cancellationToken);
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return result.Entity.Id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Commands.UpdateTypeOfOccupation;
|
||||||
|
|
||||||
|
public class UpdateTypeOfOccupationCommand : IRequest
|
||||||
|
{
|
||||||
|
public required int Id { get; set; }
|
||||||
|
public required string FullName { get; set; }
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Common.Exceptions;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Cqrs.TypeOfOccupation.Commands.UpdateTypeOfOccupation;
|
||||||
|
|
||||||
|
public class UpdateTypeOfOccupationCommandHandler(ITypeOfOccupationDbContext dbContext) : IRequestHandler<UpdateTypeOfOccupationCommand>
|
||||||
|
{
|
||||||
|
public async Task Handle(UpdateTypeOfOccupationCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var entity = await dbContext.TypeOfOccupations.FirstOrDefaultAsync(t => t.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.TypeOfOccupation), nameof(Domain.Schedule.TypeOfOccupation.Id), request.Id);
|
||||||
|
|
||||||
|
entity.FullName = request.FullName;
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
19
Application/DependencyInjection.cs
Normal file
19
Application/DependencyInjection.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Mirea.Api.DataAccess.Application.Common.Behaviors;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddApplication(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
|
||||||
|
services.AddValidatorsFromAssemblies(new[] { Assembly.GetExecutingAssembly() });
|
||||||
|
services.AddTransient(typeof(IPipelineBehavior<,>),
|
||||||
|
typeof(ValidationBehavior<,>));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
9
Application/Interfaces/DbContexts/IDbContextBase.cs
Normal file
9
Application/Interfaces/DbContexts/IDbContextBase.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts;
|
||||||
|
|
||||||
|
public interface IDbContextBase
|
||||||
|
{
|
||||||
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface ICampusDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Campus> Campuses { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface IDisciplineDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Discipline> Disciplines { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface IFacultyDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Faculty> Faculties { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface IGroupDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Group> Groups { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface ILectureHallDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<LectureHall> LectureHalls { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface ILessonAssociationDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<LessonAssociation> LessonAssociations { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface ILessonDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Lesson> Lessons { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface IProfessorDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<Professor> Professors { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
|
||||||
|
public interface ITypeOfOccupationDbContext : IDbContextBase
|
||||||
|
{
|
||||||
|
DbSet<TypeOfOccupation> TypeOfOccupations { get; set; }
|
||||||
|
}
|
20
Backend.sln
20
Backend.sln
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.8.34330.188
|
VisualStudioVersion = 17.8.34330.188
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{C27FB5CD-6A70-4FB2-847A-847B34806902}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{C27FB5CD-6A70-4FB2-847A-847B34806902}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Endpoint", "Endpoint\Endpoint.csproj", "{F3A1D12E-F5B2-4339-9966-DBF869E78357}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Endpoint", "Endpoint\Endpoint.csproj", "{F3A1D12E-F5B2-4339-9966-DBF869E78357}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -17,6 +17,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution",
|
|||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{C27FB5CD-6A70-4FB2-847A-847B34806902} = {C27FB5CD-6A70-4FB2-847A-847B34806902}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Persistence\Persistence.csproj", "{4C1E558F-633F-438E-AC3A-61CDDED917C5}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4} = {E7F0A4D4-B032-4BB9-9526-1AF688F341A4}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -31,6 +41,14 @@ Global
|
|||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
14
Domain/Schedule/Campus.cs
Normal file
14
Domain/Schedule/Campus.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Campus
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string CodeName { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
public string? Address { get; set; }
|
||||||
|
|
||||||
|
public List<Faculty>? Faculties { get; set; }
|
||||||
|
public List<LectureHall>? LectureHalls { get; set; }
|
||||||
|
}
|
11
Domain/Schedule/Discipline.cs
Normal file
11
Domain/Schedule/Discipline.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Discipline
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public List<Lesson>? Lessons { get; set; }
|
||||||
|
}
|
14
Domain/Schedule/Faculty.cs
Normal file
14
Domain/Schedule/Faculty.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Faculty
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public int? CampusId { get; set; }
|
||||||
|
public Campus? Campus { get; set; }
|
||||||
|
|
||||||
|
public List<Group>? Groups { get; set; }
|
||||||
|
}
|
14
Domain/Schedule/Group.cs
Normal file
14
Domain/Schedule/Group.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Group
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public int? FacultyId { get; set; }
|
||||||
|
public Faculty? Faculty { get; set; }
|
||||||
|
|
||||||
|
public List<Lesson>? Lessons { get; set; }
|
||||||
|
}
|
14
Domain/Schedule/LectureHall.cs
Normal file
14
Domain/Schedule/LectureHall.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class LectureHall
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public int CampusId { get; set; }
|
||||||
|
public Campus? Campus { get; set; }
|
||||||
|
|
||||||
|
public List<LessonAssociation>? LessonAssociations { get; set; }
|
||||||
|
}
|
21
Domain/Schedule/Lesson.cs
Normal file
21
Domain/Schedule/Lesson.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Lesson
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public bool IsEven { get; set; }
|
||||||
|
public DayOfWeek DayOfWeek { get; set; }
|
||||||
|
public int PairNumber { get; set; }
|
||||||
|
|
||||||
|
public int GroupId { get; set; }
|
||||||
|
public Group? Group { get; set; }
|
||||||
|
public int TypeOfOccupationId { get; set; }
|
||||||
|
public TypeOfOccupation? TypeOfOccupation { get; set; }
|
||||||
|
public int DisciplineId { get; set; }
|
||||||
|
public Discipline? Discipline { get; set; }
|
||||||
|
|
||||||
|
public List<LessonAssociation>? LessonAssociations { get; set; }
|
||||||
|
}
|
14
Domain/Schedule/LessonAssociation.cs
Normal file
14
Domain/Schedule/LessonAssociation.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class LessonAssociation
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? LinkToMeet { get; set; }
|
||||||
|
|
||||||
|
public int LessonId { get; set; }
|
||||||
|
public Lesson? Lesson { get; set; }
|
||||||
|
public int? ProfessorId { get; set; }
|
||||||
|
public Professor? Professor { get; set; }
|
||||||
|
public int? LectureHallId { get; set; }
|
||||||
|
public LectureHall? LectureHall { get; set; }
|
||||||
|
}
|
12
Domain/Schedule/Professor.cs
Normal file
12
Domain/Schedule/Professor.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class Professor
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public string? AltName { get; set; }
|
||||||
|
|
||||||
|
public List<LessonAssociation>? LessonAssociations { get; set; }
|
||||||
|
}
|
12
Domain/Schedule/TypeOfOccupation.cs
Normal file
12
Domain/Schedule/TypeOfOccupation.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
public class TypeOfOccupation
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public required string ShortName { get; set; }
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
|
||||||
|
public List<Lesson>? Lessons { get; set; }
|
||||||
|
}
|
36
Endpoint/ConfigureSwaggerOptions.cs
Normal file
36
Endpoint/ConfigureSwaggerOptions.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Mirea.Api.Endpoint;
|
||||||
|
|
||||||
|
public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions>
|
||||||
|
{
|
||||||
|
public void Configure(SwaggerGenOptions options)
|
||||||
|
{
|
||||||
|
foreach (var description in provider.ApiVersionDescriptions)
|
||||||
|
{
|
||||||
|
options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
|
||||||
|
{
|
||||||
|
var info = new OpenApiInfo()
|
||||||
|
{
|
||||||
|
Title = "MIREA Schedule Web API",
|
||||||
|
Version = description.ApiVersion.ToString(),
|
||||||
|
Description = "This API provides a convenient interface for retrieving data stored in the database. Special attention was paid to the lightweight and easy transfer of all necessary data. Made by the Winsomnia team.",
|
||||||
|
Contact = new OpenApiContact { Name = "Author name", Email = "support@winsomnia.net" },
|
||||||
|
License = new OpenApiLicense { Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT") }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (description.IsDeprecated)
|
||||||
|
info.Description += " This API version has been deprecated.";
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Controllers;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class WeatherForecastController : ControllerBase
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet(Name = "GetWeatherForecast")]
|
|
||||||
public IEnumerable<WeatherForecast> Get()
|
|
||||||
{
|
|
||||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
||||||
})
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,15 +11,25 @@
|
|||||||
<AssemblyName>Mirea.Api.Endpoint</AssemblyName>
|
<AssemblyName>Mirea.Api.Endpoint</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>false</InvariantGlobalization>
|
||||||
<UserSecretsId>65cea060-88bf-4e35-9cfb-18fc996a8f05</UserSecretsId>
|
<UserSecretsId>65cea060-88bf-4e35-9cfb-18fc996a8f05</UserSecretsId>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
<DockerfileContext>.</DockerfileContext>
|
<DockerfileContext>.</DockerfileContext>
|
||||||
|
<SignAssembly>False</SignAssembly>
|
||||||
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
<DocumentationFile>docs.xml</DocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore.Versioning" Version="2.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\Persistence\Persistence.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
24
Endpoint/EnvironmentManager.cs
Normal file
24
Endpoint/EnvironmentManager.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Mirea.Api.Endpoint;
|
||||||
|
|
||||||
|
internal static class EnvironmentManager
|
||||||
|
{
|
||||||
|
public static void LoadEnvironment(string filePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filePath)) return;
|
||||||
|
|
||||||
|
foreach (var line in File.ReadAllLines(filePath))
|
||||||
|
{
|
||||||
|
var parts = line.Split(
|
||||||
|
'=',
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
if (parts.Length != 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Environment.SetEnvironmentVariable(parts[0].Trim(), parts[1][..(parts[1].Contains('#') ? parts[1].IndexOf('#') : parts[1].Length)].Trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +1,114 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Mirea.Api.DataAccess.Application;
|
||||||
|
using Mirea.Api.DataAccess.Persistence;
|
||||||
|
using Mirea.Api.Endpoint.Properties;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint;
|
namespace Mirea.Api.Endpoint;
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
private static IConfigurationRoot ConfigureEnvironment()
|
||||||
|
{
|
||||||
|
EnvironmentManager.LoadEnvironment(".env");
|
||||||
|
var environmentVariables = Environment.GetEnvironmentVariables()
|
||||||
|
.OfType<DictionaryEntry>()
|
||||||
|
.ToDictionary(
|
||||||
|
entry => entry.Key.ToString() ?? string.Empty,
|
||||||
|
entry => entry.Value?.ToString() ?? string.Empty
|
||||||
|
);
|
||||||
|
|
||||||
|
var result = new ConfigurationBuilder().AddInMemoryCollection(environmentVariables!);
|
||||||
|
|
||||||
|
return result.Build();
|
||||||
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Configuration.AddConfiguration(ConfigureEnvironment());
|
||||||
|
builder.Configuration.AddJsonFile(Settings.FilePath, optional: true, reloadOnChange: true);
|
||||||
|
|
||||||
// Add services to the container.
|
builder.Services.AddApplication();
|
||||||
|
builder.Services.AddPersistence(builder.Configuration);
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowAll", policy =>
|
||||||
|
{
|
||||||
|
policy.AllowAnyHeader();
|
||||||
|
policy.AllowAnyMethod();
|
||||||
|
policy.AllowAnyOrigin();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddApiVersioning(options =>
|
||||||
|
{
|
||||||
|
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||||
|
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||||
|
options.ReportApiVersions = true;
|
||||||
|
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddVersionedApiExplorer(options =>
|
||||||
|
{
|
||||||
|
options.GroupNameFormat = "'v'VVV";
|
||||||
|
options.SubstituteApiVersionInUrl = true;
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.OperationFilter<SwaggerDefaultValues>();
|
||||||
|
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
|
||||||
|
|
||||||
|
var xmlPath = Path.Combine(basePath, "docs.xml");
|
||||||
|
options.IncludeXmlComments(xmlPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
// Write configurations
|
||||||
|
foreach (var item in app.Configuration.AsEnumerable())
|
||||||
|
Console.WriteLine($"{item.Key}:{item.Value}");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var uber = app.Services.CreateScope().ServiceProvider.GetService<UberDbContext>();
|
||||||
|
DbInitializer.Initialize(uber!);
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI(options =>
|
||||||
|
{
|
||||||
|
var provider = app.Services.GetService<IApiVersionDescriptionProvider>();
|
||||||
|
|
||||||
|
foreach (var description in provider!.ApiVersionDescriptions)
|
||||||
|
{
|
||||||
|
var url = $"/swagger/{description.GroupName}/swagger.json";
|
||||||
|
var name = description.GroupName.ToUpperInvariant();
|
||||||
|
options.SwaggerEndpoint(url, name);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
36
Endpoint/Properties/Settings.cs
Normal file
36
Endpoint/Properties/Settings.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Mirea.Api.DataAccess.Persistence.Properties;
|
||||||
|
|
||||||
|
namespace Mirea.Api.Endpoint.Properties;
|
||||||
|
|
||||||
|
public class EmailSettings
|
||||||
|
{
|
||||||
|
public string? Server { get; set; }
|
||||||
|
public string? User { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
public string? From { get; set; }
|
||||||
|
public int? Port { get; set; }
|
||||||
|
public bool? Ssl { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LogSettings
|
||||||
|
{
|
||||||
|
public bool EnableLogToFile { get; set; }
|
||||||
|
public string? LogFilePath { get; set; }
|
||||||
|
public string? LogFileName { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScheduleSettings
|
||||||
|
{
|
||||||
|
// Every 6 hours
|
||||||
|
public string CronUpdateSchedule { get; set; } = "0 0 0/6 * * *";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Settings
|
||||||
|
{
|
||||||
|
public const string FilePath = "Settings.json";
|
||||||
|
|
||||||
|
public EmailSettings? EmailSettings { get; set; }
|
||||||
|
public LogSettings? LogSettings { get; set; }
|
||||||
|
public DbSettings? DbSettings { get; set; }
|
||||||
|
public ScheduleSettings? ScheduleSettings { get; set; }
|
||||||
|
}
|
55
Endpoint/SwaggerDefaultValues.cs
Normal file
55
Endpoint/SwaggerDefaultValues.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Mirea.Api.Endpoint;
|
||||||
|
|
||||||
|
public class SwaggerDefaultValues : IOperationFilter
|
||||||
|
{
|
||||||
|
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||||
|
{
|
||||||
|
var apiDescription = context.ApiDescription;
|
||||||
|
operation.Deprecated |= apiDescription.IsDeprecated();
|
||||||
|
|
||||||
|
foreach (var responseType in context.ApiDescription.SupportedResponseTypes)
|
||||||
|
{
|
||||||
|
var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString();
|
||||||
|
var response = operation.Responses[responseKey];
|
||||||
|
|
||||||
|
foreach (var contentType in response.Content.Keys)
|
||||||
|
{
|
||||||
|
if (responseType.ApiResponseFormats.All(x => x.MediaType != contentType))
|
||||||
|
{
|
||||||
|
response.Content.Remove(contentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation.Parameters == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var parameter in operation.Parameters)
|
||||||
|
{
|
||||||
|
var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
|
||||||
|
|
||||||
|
parameter.Description ??= description.ModelMetadata?.Description;
|
||||||
|
|
||||||
|
if (parameter.Schema.Default == null &&
|
||||||
|
description.DefaultValue != null &&
|
||||||
|
description.DefaultValue is not DBNull &&
|
||||||
|
description.ModelMetadata is ModelMetadata modelMetadata)
|
||||||
|
{
|
||||||
|
var json = JsonSerializer.Serialize(description.DefaultValue, modelMetadata.ModelType);
|
||||||
|
parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter.Required |= description.IsRequired;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint;
|
|
||||||
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateOnly Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
}
|
|
17
Persistence/Contexts/Schedule/CampusDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/CampusDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class CampusDbContext(DbContextOptions<CampusDbContext> options) : DbContext(options), ICampusDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Campus> Campuses { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new CampusConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/DisciplineDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/DisciplineDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class DisciplineDbContext(DbContextOptions<DisciplineDbContext> options) : DbContext(options), IDisciplineDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Discipline> Disciplines { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new DisciplineConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/FacultyDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/FacultyDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class FacultyDbContext(DbContextOptions<FacultyDbContext> options) : DbContext(options), IFacultyDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Faculty> Faculties { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new FacultyConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/GroupDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/GroupDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class GroupDbContext(DbContextOptions<GroupDbContext> options) : DbContext(options), IGroupDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Group> Groups { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new GroupConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/LectureHallDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/LectureHallDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class LectureHallDbContext(DbContextOptions<LectureHallDbContext> options) : DbContext(options), ILectureHallDbContext
|
||||||
|
{
|
||||||
|
public DbSet<LectureHall> LectureHalls { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new LectureHallConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/LessonAssociationDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/LessonAssociationDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class LessonAssociationDbContext(DbContextOptions<LessonAssociationDbContext> options) : DbContext(options), ILessonAssociationDbContext
|
||||||
|
{
|
||||||
|
public DbSet<LessonAssociation> LessonAssociations { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/LessonDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/LessonDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class LessonDbContext(DbContextOptions<LessonDbContext> options) : DbContext(options), ILessonDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Lesson> Lessons { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/ProfessorDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/ProfessorDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class ProfessorDbContext(DbContextOptions<ProfessorDbContext> options) : DbContext(options), IProfessorDbContext
|
||||||
|
{
|
||||||
|
public DbSet<Professor> Professors { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new ProfessorConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
17
Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs
Normal file
17
Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
|
||||||
|
public class TypeOfOccupationDbContext(DbContextOptions<TypeOfOccupationDbContext> options) : DbContext(options), ITypeOfOccupationDbContext
|
||||||
|
{
|
||||||
|
public DbSet<TypeOfOccupation> TypeOfOccupations { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration());
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
11
Persistence/DbInitializer.cs
Normal file
11
Persistence/DbInitializer.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence;
|
||||||
|
|
||||||
|
public static class DbInitializer
|
||||||
|
{
|
||||||
|
public static void Initialize(DbContext dbContext)
|
||||||
|
{
|
||||||
|
dbContext.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
}
|
64
Persistence/DependencyInjection.cs
Normal file
64
Persistence/DependencyInjection.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.Properties;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var settings = configuration.GetSection(nameof(DbSettings)).Get<DbSettings>();
|
||||||
|
var connection = settings?.ConnectionStringSql;
|
||||||
|
|
||||||
|
Dictionary<DatabaseEnum, Action<DbContextOptionsBuilder>> dbConfigurations = new()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
DatabaseEnum.Mysql,
|
||||||
|
options => options.UseMySql(connection, ServerVersion.AutoDetect(connection))
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DatabaseEnum.Sqlite,
|
||||||
|
options => options.UseSqlite(connection)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DatabaseEnum.PostgresSql,
|
||||||
|
options => options.UseNpgsql(connection)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dbConfigurations.TryGetValue((DatabaseEnum)settings?.TypeDatabase!, out var dbConfig))
|
||||||
|
{
|
||||||
|
services.AddDbContext<CampusDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<DisciplineDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<FacultyDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<GroupDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<LectureHallDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<LessonAssociationDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<ProfessorDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<LessonDbContext>(dbConfig);
|
||||||
|
services.AddDbContext<TypeOfOccupationDbContext>(dbConfig);
|
||||||
|
|
||||||
|
services.AddDbContext<UberDbContext>(dbConfig);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new NotSupportedException("Unsupported database type");
|
||||||
|
|
||||||
|
services.AddScoped<ICampusDbContext>(provider => provider.GetService<CampusDbContext>()!);
|
||||||
|
services.AddScoped<IDisciplineDbContext>(provider => provider.GetService<DisciplineDbContext>()!);
|
||||||
|
services.AddScoped<IFacultyDbContext>(provider => provider.GetService<FacultyDbContext>()!);
|
||||||
|
services.AddScoped<IGroupDbContext>(provider => provider.GetService<GroupDbContext>()!);
|
||||||
|
services.AddScoped<ILectureHallDbContext>(provider => provider.GetService<LectureHallDbContext>()!);
|
||||||
|
services.AddScoped<ILessonAssociationDbContext>(provider => provider.GetService<LessonAssociationDbContext>()!);
|
||||||
|
services.AddScoped<IProfessorDbContext>(provider => provider.GetService<ProfessorDbContext>()!);
|
||||||
|
services.AddScoped<ILessonDbContext>(provider => provider.GetService<LessonDbContext>()!);
|
||||||
|
services.AddScoped<ITypeOfOccupationDbContext>(provider => provider.GetService<TypeOfOccupationDbContext>()!);
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class CampusConfiguration : IEntityTypeConfiguration<Campus>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Campus> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Campus));
|
||||||
|
builder.HasKey(c => c.Id);
|
||||||
|
builder.HasIndex(c => c.Id).IsUnique();
|
||||||
|
builder.Property(c => c.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(c => c.Address).HasColumnType("TEXT").HasMaxLength(512);
|
||||||
|
builder.Property(c => c.CodeName).HasColumnType("TEXT").IsRequired().HasMaxLength(16);
|
||||||
|
builder.Property(c => c.FullName).HasColumnType("TEXT").HasMaxLength(256);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class DisciplineConfiguration : IEntityTypeConfiguration<Discipline>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Discipline> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Discipline));
|
||||||
|
builder.HasKey(d => d.Id);
|
||||||
|
builder.HasIndex(d => d.Id).IsUnique();
|
||||||
|
builder.Property(d => d.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(d => d.Name).HasColumnType("TEXT").HasMaxLength(256).IsRequired();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class FacultyConfiguration : IEntityTypeConfiguration<Faculty>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Faculty> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Faculty));
|
||||||
|
builder.HasKey(f => f.Id);
|
||||||
|
builder.HasIndex(f => f.Id).IsUnique();
|
||||||
|
builder.Property(f => f.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(f => f.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(256);
|
||||||
|
|
||||||
|
builder.Property(f => f.CampusId).HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(f => f.Campus)
|
||||||
|
.WithMany(c => c.Faculties)
|
||||||
|
.HasForeignKey(c => c.CampusId)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class GroupConfiguration : IEntityTypeConfiguration<Group>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Group> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Group));
|
||||||
|
builder.HasKey(g => g.Id);
|
||||||
|
builder.HasIndex(g => g.Id).IsUnique();
|
||||||
|
builder.Property(g => g.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(g => g.FacultyId).HasColumnType("INTEGER");
|
||||||
|
builder.Property(g => g.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(64);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(g => g.Faculty)
|
||||||
|
.WithMany(u => u.Groups)
|
||||||
|
.HasForeignKey(d => d.FacultyId)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class LectureHallConfiguration : IEntityTypeConfiguration<LectureHall>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<LectureHall> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(LectureHall));
|
||||||
|
builder.HasKey(l => l.Id);
|
||||||
|
builder.HasIndex(l => l.Id).IsUnique();
|
||||||
|
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(l => l.CampusId).HasColumnType("INTEGER").IsRequired();
|
||||||
|
builder.Property(l => l.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(64);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.Campus)
|
||||||
|
.WithMany(c => c.LectureHalls)
|
||||||
|
.HasForeignKey(d => d.CampusId)
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAssociation>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<LessonAssociation> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(LessonAssociation));
|
||||||
|
builder.HasKey(l => l.Id);
|
||||||
|
builder.HasIndex(l => l.Id).IsUnique();
|
||||||
|
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(l => l.LinkToMeet).HasColumnType("TEXT").HasMaxLength(512);
|
||||||
|
|
||||||
|
builder.Property(l => l.LessonId).HasColumnType("INTEGER").IsRequired();
|
||||||
|
builder.Property(l => l.ProfessorId).HasColumnType("INTEGER");
|
||||||
|
builder.Property(l => l.LectureHallId).HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.Lesson)
|
||||||
|
.WithMany(d => d.LessonAssociations)
|
||||||
|
.HasForeignKey(l => l.LessonId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.Professor)
|
||||||
|
.WithMany(p => p.LessonAssociations)
|
||||||
|
.HasForeignKey(l => l.ProfessorId)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.LectureHall)
|
||||||
|
.WithMany(l => l.LessonAssociations)
|
||||||
|
.HasForeignKey(l => l.LectureHallId)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class LessonConfiguration : IEntityTypeConfiguration<Lesson>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Lesson> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Lesson));
|
||||||
|
builder.HasKey(l => l.Id);
|
||||||
|
builder.HasIndex(l => l.Id).IsUnique();
|
||||||
|
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(l => l.IsEven).HasColumnType("BIT").IsRequired();
|
||||||
|
builder.Property(l => l.DayOfWeek).HasColumnType("INTEGER").IsRequired();
|
||||||
|
builder.Property(l => l.PairNumber).HasColumnType("INTEGER").IsRequired();
|
||||||
|
|
||||||
|
builder.Property(l => l.GroupId).HasColumnType("INTEGER").IsRequired();
|
||||||
|
builder.Property(l => l.TypeOfOccupationId).HasColumnType("INTEGER").IsRequired();
|
||||||
|
builder.Property(l => l.DisciplineId).HasColumnType("INTEGER").IsRequired();
|
||||||
|
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.Group)
|
||||||
|
.WithMany(g => g.Lessons)
|
||||||
|
.HasForeignKey(d => d.GroupId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.TypeOfOccupation)
|
||||||
|
.WithMany(t => t.Lessons)
|
||||||
|
.HasForeignKey(d => d.TypeOfOccupationId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(l => l.Discipline)
|
||||||
|
.WithMany(d => d.Lessons)
|
||||||
|
.HasForeignKey(l => l.DisciplineId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class ProfessorConfiguration : IEntityTypeConfiguration<Professor>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Professor> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(Professor));
|
||||||
|
builder.HasKey(p => p.Id);
|
||||||
|
builder.HasIndex(p => p.Id).IsUnique();
|
||||||
|
builder.Property(p => p.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(p => p.Name).HasColumnType("TEXT").IsRequired();
|
||||||
|
builder.Property(p => p.AltName).HasColumnType("TEXT");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccupation>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<TypeOfOccupation> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable(nameof(TypeOfOccupation));
|
||||||
|
builder.HasKey(t => t.Id);
|
||||||
|
builder.HasIndex(t => t.Id).IsUnique();
|
||||||
|
builder.Property(t => t.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
builder.Property(t => t.ShortName).HasColumnType("TEXT").IsRequired().HasMaxLength(16);
|
||||||
|
builder.Property(t => t.FullName).HasColumnType("TEXT").HasMaxLength(64);
|
||||||
|
}
|
||||||
|
}
|
32
Persistence/Persistence.csproj
Normal file
32
Persistence/Persistence.csproj
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Company>Winsomnia</Company>
|
||||||
|
<Version>1.0.0-a0</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<AssemblyName>Mirea.Api.DataAccess.Persistence</AssemblyName>
|
||||||
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Application\Application.csproj" />
|
||||||
|
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migration\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
15
Persistence/Properties/DbSettings.cs
Normal file
15
Persistence/Properties/DbSettings.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace Mirea.Api.DataAccess.Persistence.Properties;
|
||||||
|
|
||||||
|
public enum DatabaseEnum
|
||||||
|
{
|
||||||
|
Mysql,
|
||||||
|
Sqlite,
|
||||||
|
PostgresSql
|
||||||
|
}
|
||||||
|
public class DbSettings
|
||||||
|
{
|
||||||
|
public bool IsDoneConfiguration { get; set; }
|
||||||
|
public DatabaseEnum TypeDatabase { get; set; }
|
||||||
|
public required string ConnectionStringSql { get; set; }
|
||||||
|
public DatabaseEnum? MigrateTo { get; set; }
|
||||||
|
}
|
33
Persistence/UberDbContext.cs
Normal file
33
Persistence/UberDbContext.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
|
namespace Mirea.Api.DataAccess.Persistence;
|
||||||
|
|
||||||
|
public class UberDbContext(DbContextOptions<UberDbContext> options) : DbContext(options)
|
||||||
|
{
|
||||||
|
public DbSet<Campus> Campuses { get; set; } = null!;
|
||||||
|
public DbSet<Discipline> Disciplines { get; set; } = null!;
|
||||||
|
public DbSet<Faculty> Faculties { get; set; } = null!;
|
||||||
|
public DbSet<Group> Groups { get; set; } = null!;
|
||||||
|
public DbSet<LectureHall> LectureHalls { get; set; } = null!;
|
||||||
|
public DbSet<LessonAssociation> LessonAssociations { get; set; } = null!;
|
||||||
|
public DbSet<Lesson> Lessons { get; set; } = null!;
|
||||||
|
public DbSet<Professor> Professors { get; set; } = null!;
|
||||||
|
public DbSet<TypeOfOccupation> TypeOfOccupations { get; set; } = null!;
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.ApplyConfiguration(new CampusConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new DisciplineConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new FacultyConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new GroupConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LectureHallConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new ProfessorConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration());
|
||||||
|
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user