From 0837497835e71661037af7f504ae8abd9bf03841 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 28 May 2024 22:41:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B4=20=D0=BD=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=B5;=20=D1=80=D0=B5=D1=81=D1=82=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D0=BA=D0=BB=D0=B8?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=D0=B4=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputerHardwareStoreDBContext.cs | 10 +- .../Migrations/20240501130816_fix.Designer.cs | 547 ------------------ .../Migrations/20240501130816_fix.cs | 80 --- .../Migrations/20240501142223_cs2.cs | 59 -- ...r.cs => 20240528172646_create.Designer.cs} | 4 +- .../Migrations/20240528172646_create.cs | 432 ++++++++++++++ .../Controllers/ComponentController.cs | 87 +++ .../Controllers/ProductController.cs | 18 +- .../Properties/launchSettings.json | 4 +- .../appsettings.json | 9 + .../ComputerHardwareStoreREST/log4net.config | 16 + .../Controllers/HomeController.cs | 4 +- .../Controllers/StoreKeeperController.cs | 4 +- .../StoreKeeperClient/Program.cs | 25 +- .../Properties/launchSettings.json | 3 - .../StoreKeeperClient.csproj | 4 + .../StoreKeeperClient/appsettings.json | 5 +- .../VendorClient/APIClient.cs | 43 ++ ComputerHardwareStore/VendorClient/Program.cs | 21 +- .../VendorClient/VendorClient.csproj | 1 + .../VendorClient/appsettings.json | 4 +- 21 files changed, 643 insertions(+), 737 deletions(-) delete mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs delete mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs delete mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.cs rename ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/{20240501142223_cs2.Designer.cs => 20240528172646_create.Designer.cs} (99%) create mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.cs create mode 100644 ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ComponentController.cs create mode 100644 ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json create mode 100644 ComputerHardwareStore/ComputerHardwareStoreREST/log4net.config create mode 100644 ComputerHardwareStore/VendorClient/APIClient.cs diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs index 94eeb6c..c790b6d 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs @@ -7,12 +7,10 @@ namespace ComputerHardwareStoreDatabaseImplement { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseNpgsql("Host=192.168.1.61:5432;Database=computerhardwarestore;Username=compstore;Password=compstore"); - - base.OnConfiguring(optionsBuilder); - AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); - } + //optionsBuilder.UseNpgsql("Host=192.168.1.61:5432;Database=computerhardwarestore;Username=compstore;Password=compstore"); + optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=ComputerHardwareStore;Username=postgres;Password=postgres"); + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + } public virtual DbSet Components { set; get; } public virtual DbSet Products { set; get; } public virtual DbSet ProductComponents { set; get; } diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs deleted file mode 100644 index a1e4440..0000000 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs +++ /dev/null @@ -1,547 +0,0 @@ -// -using System; -using ComputerHardwareStoreDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace ComputerHardwareStoreDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputerHardwareStoreDBContext))] - [Migration("20240501130816_fix")] - partial class fix - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Price") - .HasColumnType("double precision"); - - b.Property("VendorId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("VendorId"); - - b.ToTable("Builds"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BuildId") - .HasColumnType("integer"); - - b.Property("ComponentId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("BuildId"); - - b.HasIndex("ComponentId"); - - b.ToTable("BuildComponents"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BuildId") - .HasColumnType("integer"); - - b.Property("Date") - .HasColumnType("timestamp without time zone"); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("BuildId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("double precision"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("StoreKeeperId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("StoreKeeperId"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("DateCreate") - .HasColumnType("timestamp without time zone"); - - b.Property("DateImplement") - .HasColumnType("timestamp without time zone"); - - b.Property("Status") - .HasColumnType("integer"); - - b.Property("Sum") - .HasColumnType("double precision"); - - b.HasKey("Id"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("OrderId") - .HasColumnType("integer"); - - b.Property("ProductId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.ToTable("OrderProducts"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Price") - .HasColumnType("double precision"); - - b.Property("StoreKeeperId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("StoreKeeperId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("ProductId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ProductId"); - - b.ToTable("ProductComponents"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Cost") - .HasColumnType("double precision"); - - b.Property("DateCreate") - .HasColumnType("timestamp without time zone"); - - b.Property("DateImplement") - .HasColumnType("timestamp without time zone"); - - b.Property("VendorId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("VendorId"); - - b.ToTable("Purchases"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BuildId") - .HasColumnType("integer"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("PurchaseId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("BuildId"); - - b.HasIndex("PurchaseId"); - - b.ToTable("PurchaseBuilds"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("ProductId") - .HasColumnType("integer"); - - b.Property("PurchaseId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("PurchaseId"); - - b.ToTable("PurchaseProducts"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("StoreKeepers"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Vendors"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", "Vendor") - .WithMany("Builds") - .HasForeignKey("VendorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Vendor"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") - .WithMany("Components") - .HasForeignKey("BuildId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component") - .WithMany() - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Build"); - - b.Navigation("Component"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") - .WithMany() - .HasForeignKey("BuildId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Build"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", "StoreKeeperЗЛ") - .WithMany("Components") - .HasForeignKey("StoreKeeperId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("StoreKeeperЗЛ"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Order", "Order") - .WithMany("Products") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", null) - .WithMany("Products") - .HasForeignKey("StoreKeeperId"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component") - .WithMany("ProductComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") - .WithMany("Components") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", null) - .WithMany("Purchases") - .HasForeignKey("VendorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") - .WithMany() - .HasForeignKey("BuildId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase") - .WithMany("Builds") - .HasForeignKey("PurchaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Build"); - - b.Navigation("Purchase"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b => - { - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase") - .WithMany("Products") - .HasForeignKey("PurchaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("Purchase"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => - { - b.Navigation("Components"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => - { - b.Navigation("ProductComponents"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b => - { - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => - { - b.Navigation("Components"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => - { - b.Navigation("Builds"); - - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b => - { - b.Navigation("Components"); - - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b => - { - b.Navigation("Builds"); - - b.Navigation("Purchases"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs deleted file mode 100644 index 8c1a376..0000000 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputerHardwareStoreDatabaseImplement.Migrations -{ - /// - public partial class fix : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Products_ProductId", - table: "Orders"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ProductId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "Count", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ProductId", - table: "Orders"); - - migrationBuilder.CreateIndex( - name: "IX_Comments_BuildId", - table: "Comments", - column: "BuildId"); - - migrationBuilder.AddForeignKey( - name: "FK_Comments_Builds_BuildId", - table: "Comments", - column: "BuildId", - principalTable: "Builds", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Comments_Builds_BuildId", - table: "Comments"); - - migrationBuilder.DropIndex( - name: "IX_Comments_BuildId", - table: "Comments"); - - migrationBuilder.AddColumn( - name: "Count", - table: "Orders", - type: "integer", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "ProductId", - table: "Orders", - type: "integer", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ProductId", - table: "Orders", - column: "ProductId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Products_ProductId", - table: "Orders", - column: "ProductId", - principalTable: "Products", - principalColumn: "Id"); - } - } -} diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.cs deleted file mode 100644 index 0549943..0000000 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputerHardwareStoreDatabaseImplement.Migrations -{ - /// - public partial class cs2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Count", - table: "Orders", - type: "integer", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "ProductId", - table: "Orders", - type: "integer", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ProductId", - table: "Orders", - column: "ProductId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Products_ProductId", - table: "Orders", - column: "ProductId", - principalTable: "Products", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Products_ProductId", - table: "Orders"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ProductId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "Count", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ProductId", - table: "Orders"); - } - } -} diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.Designer.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.Designer.cs similarity index 99% rename from ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.Designer.cs rename to ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.Designer.cs index cbd252a..6d870c9 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501142223_cs2.Designer.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ComputerHardwareStoreDatabaseImplement.Migrations { [DbContext(typeof(ComputerHardwareStoreDBContext))] - [Migration("20240501142223_cs2")] - partial class cs2 + [Migration("20240528172646_create")] + partial class create { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.cs new file mode 100644 index 0000000..7b44e2f --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240528172646_create.cs @@ -0,0 +1,432 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputerHardwareStoreDatabaseImplement.Migrations +{ + /// + public partial class create : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "StoreKeepers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Login = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StoreKeepers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Vendors", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Login = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Vendors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + table.ForeignKey( + name: "FK_Components_StoreKeepers_StoreKeeperId", + column: x => x.StoreKeeperId, + principalTable: "StoreKeepers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false), + StoreKeeperId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + table.ForeignKey( + name: "FK_Products_StoreKeepers_StoreKeeperId", + column: x => x.StoreKeeperId, + principalTable: "StoreKeepers", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Builds", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false), + VendorId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Builds", x => x.Id); + table.ForeignKey( + name: "FK_Builds_Vendors_VendorId", + column: x => x.VendorId, + principalTable: "Vendors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Purchases", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + VendorId = table.Column(type: "integer", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + DateCreate = table.Column(type: "timestamp without time zone", nullable: false), + DateImplement = table.Column(type: "timestamp without time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Purchases", x => x.Id); + table.ForeignKey( + name: "FK_Purchases_Vendors_VendorId", + column: x => x.VendorId, + principalTable: "Vendors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Count = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + Status = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp without time zone", nullable: false), + DateImplement = table.Column(type: "timestamp without time zone", nullable: true), + ProductId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "ProductComponents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ProductId = table.Column(type: "integer", nullable: false), + ComponentId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductComponents", x => x.Id); + table.ForeignKey( + name: "FK_ProductComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ProductComponents_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "BuildComponents", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + BuildId = table.Column(type: "integer", nullable: false), + ComponentId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BuildComponents", x => x.Id); + table.ForeignKey( + name: "FK_BuildComponents_Builds_BuildId", + column: x => x.BuildId, + principalTable: "Builds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_BuildComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Comments", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "timestamp without time zone", nullable: false), + Text = table.Column(type: "text", nullable: false), + BuildId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Comments", x => x.Id); + table.ForeignKey( + name: "FK_Comments_Builds_BuildId", + column: x => x.BuildId, + principalTable: "Builds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PurchaseBuilds", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PurchaseId = table.Column(type: "integer", nullable: false), + BuildId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PurchaseBuilds", x => x.Id); + table.ForeignKey( + name: "FK_PurchaseBuilds_Builds_BuildId", + column: x => x.BuildId, + principalTable: "Builds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PurchaseBuilds_Purchases_PurchaseId", + column: x => x.PurchaseId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PurchaseProducts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PurchaseId = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PurchaseProducts", x => x.Id); + table.ForeignKey( + name: "FK_PurchaseProducts_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PurchaseProducts_Purchases_PurchaseId", + column: x => x.PurchaseId, + principalTable: "Purchases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderProducts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + OrderId = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderProducts", x => x.Id); + table.ForeignKey( + name: "FK_OrderProducts_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OrderProducts_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_BuildComponents_BuildId", + table: "BuildComponents", + column: "BuildId"); + + migrationBuilder.CreateIndex( + name: "IX_BuildComponents_ComponentId", + table: "BuildComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_Builds_VendorId", + table: "Builds", + column: "VendorId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_BuildId", + table: "Comments", + column: "BuildId"); + + migrationBuilder.CreateIndex( + name: "IX_Components_StoreKeeperId", + table: "Components", + column: "StoreKeeperId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderProducts_OrderId", + table: "OrderProducts", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderProducts_ProductId", + table: "OrderProducts", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ProductId", + table: "Orders", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_ProductComponents_ComponentId", + table: "ProductComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ProductComponents_ProductId", + table: "ProductComponents", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Products_StoreKeeperId", + table: "Products", + column: "StoreKeeperId"); + + migrationBuilder.CreateIndex( + name: "IX_PurchaseBuilds_BuildId", + table: "PurchaseBuilds", + column: "BuildId"); + + migrationBuilder.CreateIndex( + name: "IX_PurchaseBuilds_PurchaseId", + table: "PurchaseBuilds", + column: "PurchaseId"); + + migrationBuilder.CreateIndex( + name: "IX_PurchaseProducts_ProductId", + table: "PurchaseProducts", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_PurchaseProducts_PurchaseId", + table: "PurchaseProducts", + column: "PurchaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_VendorId", + table: "Purchases", + column: "VendorId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "BuildComponents"); + + migrationBuilder.DropTable( + name: "Comments"); + + migrationBuilder.DropTable( + name: "OrderProducts"); + + migrationBuilder.DropTable( + name: "ProductComponents"); + + migrationBuilder.DropTable( + name: "PurchaseBuilds"); + + migrationBuilder.DropTable( + name: "PurchaseProducts"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Builds"); + + migrationBuilder.DropTable( + name: "Purchases"); + + migrationBuilder.DropTable( + name: "Products"); + + migrationBuilder.DropTable( + name: "Vendors"); + + migrationBuilder.DropTable( + name: "StoreKeepers"); + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ComponentController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ComponentController.cs new file mode 100644 index 0000000..33c5916 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ComponentController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class ProductController : Controller + { + private readonly ILogger _logger; + private readonly IProductStorage _storage; + + public ProductController(ILogger logger, IProductStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] ProductSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] ProductSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs index 33c5916..ba1ec0a 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs @@ -7,19 +7,19 @@ namespace ComputerHardwareStoreREST.Controllers { [ApiController] [Route("[controller]")] - public class ProductController : Controller + public class ComponentController : Controller { - private readonly ILogger _logger; - private readonly IProductStorage _storage; + private readonly ILogger _logger; + private readonly IComponentStorage _storage; - public ProductController(ILogger logger, IProductStorage storage) + public ComponentController(ILogger logger, IComponentStorage storage) { _logger = logger; _storage = storage; } [HttpPost("get/filter")] - public IActionResult GetByFilter([FromBody] ProductSearchModel model) + public IActionResult GetByFilter([FromBody] ComponentSearchModel model) { try { @@ -32,7 +32,7 @@ namespace ComputerHardwareStoreREST.Controllers } } [HttpPost("get")] - public IActionResult GetById([FromBody] ProductSearchModel model) + public IActionResult GetById([FromBody] ComponentSearchModel model) { try { @@ -45,7 +45,7 @@ namespace ComputerHardwareStoreREST.Controllers } } [HttpPost("create")] - public IActionResult Create([FromBody] ProductBindingModel model) + public IActionResult Create([FromBody] ComponentBindingModel model) { try { @@ -58,7 +58,7 @@ namespace ComputerHardwareStoreREST.Controllers } } [HttpPut("update")] - public IActionResult Update([FromBody] ProductBindingModel model) + public IActionResult Update([FromBody] ComponentBindingModel model) { try { @@ -71,7 +71,7 @@ namespace ComputerHardwareStoreREST.Controllers } } [HttpPost("delete")] - public IActionResult Delete([FromBody] ProductBindingModel model) + public IActionResult Delete([FromBody] ComponentBindingModel model) { try { diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Properties/launchSettings.json b/ComputerHardwareStore/ComputerHardwareStoreREST/Properties/launchSettings.json index f7c2a58..fcff0ab 100644 --- a/ComputerHardwareStore/ComputerHardwareStoreREST/Properties/launchSettings.json +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Properties/launchSettings.json @@ -2,11 +2,13 @@ "profiles": { "ComputerHardwareStoreREST": { "commandName": "Project", + "dotnetRunMessages": true, "launchBrowser": true, + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "https://localhost:63872;http://localhost:63873" + "applicationUrl": "https://localhost:8080;http://localhost:8081" } } } \ No newline at end of file diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json new file mode 100644 index 0000000..03b4c0d --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/log4net.config b/ComputerHardwareStore/ComputerHardwareStoreREST/log4net.config new file mode 100644 index 0000000..b408289 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs index a6b11af..ef97772 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs +++ b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs @@ -6,7 +6,9 @@ using ComputerHardwareStoreContracts.BindingModels; namespace StoreKeeperClient.Controllers { - public class HomeController : Controller + [Route("api/[controller]/[action]")] + [ApiController] + public class HomeController : Controller { private readonly ILogger _logger; diff --git a/ComputerHardwareStore/StoreKeeperClient/Controllers/StoreKeeperController.cs b/ComputerHardwareStore/StoreKeeperClient/Controllers/StoreKeeperController.cs index 7eecc11..7856576 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Controllers/StoreKeeperController.cs +++ b/ComputerHardwareStore/StoreKeeperClient/Controllers/StoreKeeperController.cs @@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc; namespace StoreKeeperClient.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class StoreKeeperController : Controller { private readonly ILogger _logger; @@ -224,7 +226,7 @@ namespace StoreKeeperClient.Controllers componentsViewModels.FirstOrDefault(x => x.Id == component.Id)!, component.Quantity )); - price += component.Quantity * componentsViewModels.FirstOrDefault(x => x.Id == component.Id)!.ComponentPrice; + price += component.Quantity * componentsViewModels.FirstOrDefault(x => x.Id == component.Id)!.Cost; } _productLogic.Create( diff --git a/ComputerHardwareStore/StoreKeeperClient/Program.cs b/ComputerHardwareStore/StoreKeeperClient/Program.cs index c525216..91cc58d 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Program.cs +++ b/ComputerHardwareStore/StoreKeeperClient/Program.cs @@ -1,28 +1,25 @@ -using ComputerHardwareStoreContracts.BusinessLogicsContracts; -using ComputerHardwareStoreContracts.StorageContracts; -using ComputerHardwareStoreDatabaseImplement.Implements; -using ComputerHardwareStoreBusinessLogic.BusinessLogic; +using StoreKeeperClient; var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); } +app.UseStaticFiles(); +app.UseRouting(); + app.UseAuthorization(); -app.MapControllers(); +app.MapControllerRoute( +name: "default", +pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/ComputerHardwareStore/StoreKeeperClient/Properties/launchSettings.json b/ComputerHardwareStore/StoreKeeperClient/Properties/launchSettings.json index 4e32c5d..6fb0e56 100644 --- a/ComputerHardwareStore/StoreKeeperClient/Properties/launchSettings.json +++ b/ComputerHardwareStore/StoreKeeperClient/Properties/launchSettings.json @@ -13,7 +13,6 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", "applicationUrl": "http://localhost:5062", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" @@ -23,7 +22,6 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", "applicationUrl": "https://localhost:7291;http://localhost:5062", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" @@ -32,7 +30,6 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/ComputerHardwareStore/StoreKeeperClient/StoreKeeperClient.csproj b/ComputerHardwareStore/StoreKeeperClient/StoreKeeperClient.csproj index 78fd257..a2323eb 100644 --- a/ComputerHardwareStore/StoreKeeperClient/StoreKeeperClient.csproj +++ b/ComputerHardwareStore/StoreKeeperClient/StoreKeeperClient.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/ComputerHardwareStore/StoreKeeperClient/appsettings.json b/ComputerHardwareStore/StoreKeeperClient/appsettings.json index 3ebedf1..aec5e69 100644 --- a/ComputerHardwareStore/StoreKeeperClient/appsettings.json +++ b/ComputerHardwareStore/StoreKeeperClient/appsettings.json @@ -6,6 +6,5 @@ } }, "AllowedHosts": "*", - - "IPAddress": "http://localhost:7291/" -} + "IPAddress": "http://localhost:8081/" +} \ No newline at end of file diff --git a/ComputerHardwareStore/VendorClient/APIClient.cs b/ComputerHardwareStore/VendorClient/APIClient.cs new file mode 100644 index 0000000..90666bf --- /dev/null +++ b/ComputerHardwareStore/VendorClient/APIClient.cs @@ -0,0 +1,43 @@ +using ComputerHardwareStoreContracts.ViewModels; +using Newtonsoft.Json; +using System.Net.Http.Headers; +using System.Text; + +namespace VendorClient +{ + public static class APIClient + { + private static readonly HttpClient _client = new(); + public static StoreKeeperViewModel? Client { get; set; } = null; + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + var response = _client.PostAsync(requestUrl, data); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/ComputerHardwareStore/VendorClient/Program.cs b/ComputerHardwareStore/VendorClient/Program.cs index df2434c..f13d07e 100644 --- a/ComputerHardwareStore/VendorClient/Program.cs +++ b/ComputerHardwareStore/VendorClient/Program.cs @@ -1,23 +1,26 @@ +using VendorClient; + var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); -// Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); } +app.UseStaticFiles(); +app.UseRouting(); + app.UseAuthorization(); -app.MapControllers(); +app.MapControllerRoute( +name: "default", +pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/ComputerHardwareStore/VendorClient/VendorClient.csproj b/ComputerHardwareStore/VendorClient/VendorClient.csproj index d63e0fb..9c087cf 100644 --- a/ComputerHardwareStore/VendorClient/VendorClient.csproj +++ b/ComputerHardwareStore/VendorClient/VendorClient.csproj @@ -7,6 +7,7 @@ + diff --git a/ComputerHardwareStore/VendorClient/appsettings.json b/ComputerHardwareStore/VendorClient/appsettings.json index 8dc0e3a..aec5e69 100644 --- a/ComputerHardwareStore/VendorClient/appsettings.json +++ b/ComputerHardwareStore/VendorClient/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:7085/" -} + "IPAddress": "http://localhost:8081/" +} \ No newline at end of file