From 5d7beec9c13eeeea1f345e87fe645bdf37c38875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D0=B8=D1=88=D0=B8=D0=BD=D0=B0=29?= <Аришина)@DESKTOP-OUE59OV> Date: Wed, 30 Oct 2024 15:33:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20co?= =?UTF-8?q?rs=20program.cs=20=D0=B4=D0=BB=D1=8F=20=D1=84=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20241030111034_front.Designer.cs | 95 +++++++++++++++++++ Cloud/Migrations/20241030111034_front.cs | 19 ++++ Cloud/Program.cs | 14 +++ 3 files changed, 128 insertions(+) create mode 100644 Cloud/Migrations/20241030111034_front.Designer.cs create mode 100644 Cloud/Migrations/20241030111034_front.cs diff --git a/Cloud/Migrations/20241030111034_front.Designer.cs b/Cloud/Migrations/20241030111034_front.Designer.cs new file mode 100644 index 0000000..017938b --- /dev/null +++ b/Cloud/Migrations/20241030111034_front.Designer.cs @@ -0,0 +1,95 @@ +// +using Cloud; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Cloud.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20241030111034_front")] + partial class front + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Cloud.Models.Farm", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("RaspberryMacAddr") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Farms"); + }); + + modelBuilder.Entity("Cloud.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Cloud.Models.Farm", b => + { + b.HasOne("Cloud.Models.User", "User") + .WithMany("Farms") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Cloud.Models.User", b => + { + b.Navigation("Farms"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Cloud/Migrations/20241030111034_front.cs b/Cloud/Migrations/20241030111034_front.cs new file mode 100644 index 0000000..9ca6bc8 --- /dev/null +++ b/Cloud/Migrations/20241030111034_front.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Cloud.Migrations +{ + public partial class front : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Cloud/Program.cs b/Cloud/Program.cs index 6f77533..d1e6521 100644 --- a/Cloud/Program.cs +++ b/Cloud/Program.cs @@ -33,6 +33,17 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) builder.Services.AddDbContext(options => options.UseNpgsql("Host=localhost;Port=5438;Database=main_database;Username=postgres;Password=12345")); +// Настройка CORS +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowFrontendLocalhost", builder => + { + builder.WithOrigins("http://localhost:3000") // фронтенд + .AllowAnyHeader() + .AllowAnyMethod(); + }); +}); + builder.Services.AddControllers(); builder.Services.AddFluentValidationAutoValidation(); builder.Services.AddFluentValidationClientsideAdapters(); @@ -85,6 +96,9 @@ if (app.Environment.IsDevelopment()) app.UseHttpsRedirection(); +// Включение CORS +app.UseCors("AllowFrontendLocalhost"); + app.UseAuthentication(); app.UseAuthorization();