This commit is contained in:
romai 2024-12-11 01:51:02 +04:00
parent 796faede69
commit c5041e5fed
12 changed files with 62 additions and 26 deletions

View File

@ -16,9 +16,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Cont
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{4CCFADCD-9E80-4B66-A6D8-B6FC5490A0C0}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{4CCFADCD-9E80-4B66-A6D8-B6FC5490A0C0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation", "Presentation\Presentation.csproj", "{9359CCCA-F725-462F-AACD-8FCAE5C907E5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presentation", "Presentation\Presentation.csproj", "{9359CCCA-F725-462F-AACD-8FCAE5C907E5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "Web\Web.csproj", "{EB3EE34B-8C85-4EC8-9E78-CFBECED2E0AD}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "Web\Web.csproj", "{EB3EE34B-8C85-4EC8-9E78-CFBECED2E0AD}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{9359CCCA-F725-462F-AACD-8FCAE5C907E5} = {9359CCCA-F725-462F-AACD-8FCAE5C907E5} {9359CCCA-F725-462F-AACD-8FCAE5C907E5} = {9359CCCA-F725-462F-AACD-8FCAE5C907E5}
EndProjectSection EndProjectSection

View File

@ -13,8 +13,8 @@ using Persistence;
namespace Persistence.Migrations namespace Persistence.Migrations
{ {
[DbContext(typeof(RepositoryDbContext))] [DbContext(typeof(RepositoryDbContext))]
[Migration("20241210151814_mig2")] [Migration("20241210215030_mi")]
partial class mig2 partial class mi
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -34,7 +34,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<Guid>("RegionId") b.Property<Guid>("RegionId")
.HasColumnType("uuid"); .HasColumnType("uuid");
@ -57,7 +58,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.HasKey("Id"); b.HasKey("Id");
@ -82,7 +84,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<int>("OkatoCode") b.Property<int>("OkatoCode")
.HasColumnType("integer"); .HasColumnType("integer");

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Persistence.Migrations namespace Persistence.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class mig2 : Migration public partial class mi : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -17,7 +17,7 @@ namespace Persistence.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uuid", nullable: false), Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false), Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
Code = table.Column<int>(type: "integer", nullable: false) Code = table.Column<int>(type: "integer", nullable: false)
}, },
constraints: table => constraints: table =>
@ -30,7 +30,7 @@ namespace Persistence.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uuid", nullable: false), Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false), Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
RegionId = table.Column<Guid>(type: "uuid", nullable: false) RegionId = table.Column<Guid>(type: "uuid", nullable: false)
}, },
constraints: table => constraints: table =>
@ -49,7 +49,7 @@ namespace Persistence.Migrations
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uuid", nullable: false), Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false), Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
HouseNumbers = table.Column<List<int>>(type: "integer[]", nullable: false), HouseNumbers = table.Column<List<int>>(type: "integer[]", nullable: false),
Index = table.Column<int>(type: "integer", nullable: false), Index = table.Column<int>(type: "integer", nullable: false),
OkatoCode = table.Column<int>(type: "integer", nullable: false), OkatoCode = table.Column<int>(type: "integer", nullable: false),

View File

@ -31,7 +31,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<Guid>("RegionId") b.Property<Guid>("RegionId")
.HasColumnType("uuid"); .HasColumnType("uuid");
@ -54,7 +55,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.HasKey("Id"); b.HasKey("Id");
@ -79,7 +81,8 @@ namespace Persistence.Migrations
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<int>("OkatoCode") b.Property<int>("OkatoCode")
.HasColumnType("integer"); .HasColumnType("integer");

View File

@ -13,7 +13,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -13,5 +13,9 @@ namespace Persistence
: base(options) : base(options)
{ {
} }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(typeof(RepositoryDbContext).Assembly);
}
} }
} }

View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Persistence;
public class RepositoryDbContextFactory : IDesignTimeDbContextFactory<RepositoryDbContext>
{
public RepositoryDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Web"))
.AddJsonFile("appsettings.json")
.Build();
var connectionString = configuration.GetConnectionString("Database");
var optionsBuilder = new DbContextOptionsBuilder<RepositoryDbContext>();
optionsBuilder.UseNpgsql(connectionString);
return new RepositoryDbContext(optionsBuilder.Options);
}
}

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.38" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -9,16 +9,13 @@ using Services.Profiles;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration; var configuration = builder.Configuration;
var connectionString = builder.Configuration.GetConnectionString("Database");
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<RepositoryDbContext>(
options =>
{
options.UseNpgsql(configuration.GetConnectionString(nameof(RepositoryDbContext)));
});
builder.Services.AddScoped<IRegionService, RegionService>(); builder.Services.AddScoped<IRegionService, RegionService>();
builder.Services.AddScoped<ICityService, CityService>(); builder.Services.AddScoped<ICityService, CityService>();
@ -28,8 +25,15 @@ builder.Services.AddScoped<IRegionRepository, RegionRepository>();
builder.Services.AddScoped<ICityRepository, CityRepository>(); builder.Services.AddScoped<ICityRepository, CityRepository>();
builder.Services.AddScoped<IStreetRepository, StreetRepository>(); builder.Services.AddScoped<IStreetRepository, StreetRepository>();
builder.Services.AddDbContext<RepositoryDbContext>(
options =>
{
options.UseNpgsql(connectionString);
});
builder.Services.AddAutoMapper(typeof(MappingProfile)); builder.Services.AddAutoMapper(typeof(MappingProfile));
var app = builder.Build(); var app = builder.Build();
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseSwagger(); app.UseSwagger();

View File

@ -11,7 +11,8 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,8 +5,5 @@
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
},
"ConnectionStrings": {
"RepositoryDbContext":"Host=localhost;Port=5432;Database=AdressDb;Username=postgres;Password=postgres"
} }
} }

View File

@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"ConnectionStrings": {
"Database": "Host=localhost;Port=5432;Database=AdressDb;Username=postgres;Password=postgres"
}
} }