Compare commits
No commits in common. "feat/application-command" and "master" have entirely different histories.
feat/appli
...
master
@ -1,26 +0,0 @@
|
||||
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
|
@ -1,27 +0,0 @@
|
||||
<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>
|
@ -1,30 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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}\".") { }
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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}\".") { }
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Common.Mappings;
|
||||
|
||||
public interface IMapWith<T>
|
||||
{
|
||||
void Mapping(Profile profile) =>
|
||||
profile.CreateMap(typeof(T), GetType());
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts;
|
||||
|
||||
public interface IDbContextBase
|
||||
{
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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
|
||||
VisualStudioVersion = 17.8.34330.188
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{C27FB5CD-6A70-4FB2-847A-847B34806902}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csproj", "{C27FB5CD-6A70-4FB2-847A-847B34806902}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Endpoint", "Endpoint\Endpoint.csproj", "{F3A1D12E-F5B2-4339-9966-DBF869E78357}"
|
||||
EndProject
|
||||
@ -17,16 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution",
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -41,14 +31,6 @@ Global
|
||||
{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.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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,14 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
36
Endpoint/Controllers/WeatherForecastController.cs
Normal file
36
Endpoint/Controllers/WeatherForecastController.cs
Normal file
@ -0,0 +1,36 @@
|
||||
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,25 +11,15 @@
|
||||
<AssemblyName>Mirea.Api.Endpoint</AssemblyName>
|
||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||
<OutputType>Exe</OutputType>
|
||||
<InvariantGlobalization>false</InvariantGlobalization>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<UserSecretsId>65cea060-88bf-4e35-9cfb-18fc996a8f05</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>.</DockerfileContext>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DocumentationFile>docs.xml</DocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<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>
|
||||
|
||||
</Project>
|
@ -1,24 +0,0 @@
|
||||
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,114 +1,29 @@
|
||||
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.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;
|
||||
|
||||
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)
|
||||
{
|
||||
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddConfiguration(ConfigureEnvironment());
|
||||
builder.Configuration.AddJsonFile(Settings.FilePath, optional: true, reloadOnChange: true);
|
||||
|
||||
builder.Services.AddApplication();
|
||||
builder.Services.AddPersistence(builder.Configuration);
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
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>();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
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.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
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.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
@ -1,36 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
14
Endpoint/WeatherForecast.cs
Normal file
14
Endpoint/WeatherForecast.cs
Normal file
@ -0,0 +1,14 @@
|
||||
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; }
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Persistence;
|
||||
|
||||
public static class DbInitializer
|
||||
{
|
||||
public static void Initialize(DbContext dbContext)
|
||||
{
|
||||
dbContext.Database.EnsureCreated();
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<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>
|
@ -1,15 +0,0 @@
|
||||
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; }
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
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