Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
569 changes: 569 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
<EnablePackageVersionOverride>false</EnablePackageVersionOverride>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Itmo.Dev.Editorconfig" Version="1.0.2" />
<PackageVersion Include="Itmo.Dev.Platform.Logging" Version="1.0.89" />
<PackageVersion Include="Itmo.Dev.Platform.Postgres" Version="1.1.89" />
<PackageVersion Include="DotNet.Testcontainers" Version="1.6.0" />
<PackageVersion Include="EntityFramework" Version="6.4.4" />
<PackageVersion Include="Itmo.Dev.Editorconfig" Version="1.0.1" />
<PackageVersion Include="Itmo.Dev.Platform.Logging" Version="1.0.82" />
<PackageVersion Include="Itmo.Dev.Platform.Postgres" Version="1.1.82" />
<PackageVersion Include="Itmo.Dev.Platform.Common" Version="1.1.82" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.15" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="SourceKit.Generators.Builder" Version="1.1.24" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Itmo.Dev.Platform.Postgres" />
<PackageReference Include="Itmo.Dev.Platform.Common" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using DoctorsHelp.Application.Contracts;
using DoctorsHelp.Application.Models;
using Microsoft.Extensions.DependencyInjection;

namespace DoctorsHelp.Application.Extensions;
Expand All @@ -6,7 +8,6 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplication(this IServiceCollection collection)
{
// TODO: add services
return collection;
}
}
17 changes: 14 additions & 3 deletions src/DoctorsHelp/DoctorsHelp.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\Application\DoctorsHelp.Application\DoctorsHelp.Application.csproj"/>
<ProjectReference Include="..\Infrastructure\DoctorsHelp.Infrastructure.Persistence\DoctorsHelp.Infrastructure.Persistence.csproj"/>
<ProjectReference Include="..\Application\DoctorsHelp.Application\DoctorsHelp.Application.csproj" />
<ProjectReference Include="..\Infrastructure\DoctorsHelp.Infrastructure.Persistence\DoctorsHelp.Infrastructure.Persistence.csproj" />
<ProjectReference Include="..\Presentation\DoctorsHelp.Presentation.Http\DoctorsHelp.Presentation.Http.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Itmo.Dev.Platform.Logging"/>
<PackageReference Include="DotNet.Testcontainers" />
<PackageReference Include="Itmo.Dev.Platform.Logging" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>
<PropertyGroup>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>

<ItemGroup>
<Content Update="appsettings.*.json">
Expand Down
21 changes: 20 additions & 1 deletion src/DoctorsHelp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@
using DoctorsHelp.Application.Extensions;
using DoctorsHelp.Infrastructure.Persistence.Extensions;
using DoctorsHelp.Presentation.Http.Extensions;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Itmo.Dev.Platform.Common.Extensions;
using Itmo.Dev.Platform.Logging.Extensions;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

var postgresContainer = new TestcontainersBuilder<PostgreSqlTestcontainer>()
.WithDatabase(new PostgreSqlTestcontainerConfiguration
{
Database = "postgres",
Username = "postgres",
Password = "postgres",
})
.Build();

await postgresContainer.StartAsync();

// builder.Configuration["Infrastructure:Persistence:Postgres:Host"] = postgresContainer.Hostname;
// builder.Configuration["Infrastructure:Persistence:Postgres:Port"] = postgresContainer.Port.ToString();
// builder.Configuration["Infrastructure:Persistence:Postgres:Username"] = postgresContainer.Username;
// builder.Configuration["Infrastructure:Persistence:Postgres:Password"] = postgresContainer.Password;
// builder.Configuration["Infrastructure:Persistence:Postgres:Database"] = postgresContainer.Database;
builder.Configuration.AddUserSecrets<Program>();

builder.Services.AddOptions<JsonSerializerSettings>();
builder.Services.AddSingleton(sp => sp.GetRequiredService<IOptions<JsonSerializerSettings>>().Value);

builder.Services.AddApplication();
builder.Services.AddInfrastructurePersistence();
builder.Services.AddInfrastructurePersistence(builder.Configuration);
builder.Services
.AddControllers()
.AddNewtonsoftJson()
Expand Down
3 changes: 2 additions & 1 deletion src/DoctorsHelp/appsettings.Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Username": "postgres",
"Password": "postgres",
"SslMode": "Prefer",
"Pooling": true
"Pooling": true,
"ConnectionString": "Host=localhost;Port=6432;Database=postgres;Username=postgres;Password=postgres;SslMode=Prefer;Pooling=true"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DoctorsHelp.Application.Models;
using Microsoft.EntityFrameworkCore;

namespace DoctorsHelp.Infrastructure.Persistence.Contexts;

public class ApplicationDbContext : DbContext
{
public ApplicationDbContext() { }

public ApplicationDbContext(DbContextOptions options) : base(options) { }

required public DbSet<User> Students { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
base.OnModelCreating(modelBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<ItemGroup>
<ProjectReference Include="..\..\Application\DoctorsHelp.Application.Abstractions\DoctorsHelp.Application.Abstractions.csproj"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
using DoctorsHelp.Application.Abstractions.Persistence;
using DoctorsHelp.Infrastructure.Persistence.Contexts;
using DoctorsHelp.Infrastructure.Persistence.Migrations;
using DoctorsHelp.Infrastructure.Persistence.Plugins;
using Itmo.Dev.Platform.Postgres.Extensions;
using Itmo.Dev.Platform.Postgres.Plugins;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace DoctorsHelp.Infrastructure.Persistence.Extensions;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection)
public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection, IConfiguration configuration)
{
collection.AddPlatformPostgres(builder => builder.BindConfiguration("Infrastructure:Persistence:Postgres"));
collection.AddSingleton<IDataSourcePlugin, MappingPlugin>();

collection.AddPlatformMigrations(typeof(IAssemblyMarker).Assembly);
collection.AddHostedService<MigrationRunnerService>();

// TODO: add repositories
collection.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(configuration.GetSection("Infrastructure:Persistence:Postgres:ConnectionString").Value));
collection.AddScoped<IPersistenceContext, PersistenceContext>();

return collection;
Expand Down