diff --git a/GarmentFactory/GarmentFactory.sln b/GarmentFactory/GarmentFactory.sln index 02e0af1..0e0f5c1 100644 --- a/GarmentFactory/GarmentFactory.sln +++ b/GarmentFactory/GarmentFactory.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryListImplement EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryFileImplement", "GarmentFactoryFileImplement\GarmentFactoryFileImplement.csproj", "{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryDatabaseImplement", "GarmentFactoryDatabaseImplement\GarmentFactoryDatabaseImplement.csproj", "{0AD8F2A6-9B14-411A-A454-D1A33B170C27}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryDatabaseImplement", "GarmentFactoryDatabaseImplement\GarmentFactoryDatabaseImplement.csproj", "{0AD8F2A6-9B14-411A-A454-D1A33B170C27}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryRestApi", "GarmentFactoryRestApi\GarmentFactoryRestApi.csproj", "{45C1D0C8-F7F1-48FB-A4BA-DE1B6EB4CC25}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Debug|Any CPU.Build.0 = Debug|Any CPU {0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Release|Any CPU.ActiveCfg = Release|Any CPU {0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Release|Any CPU.Build.0 = Release|Any CPU + {45C1D0C8-F7F1-48FB-A4BA-DE1B6EB4CC25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45C1D0C8-F7F1-48FB-A4BA-DE1B6EB4CC25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45C1D0C8-F7F1-48FB-A4BA-DE1B6EB4CC25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45C1D0C8-F7F1-48FB-A4BA-DE1B6EB4CC25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs index b4c0f3d..251274b 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs @@ -11,6 +11,7 @@ namespace GarmentFactoryDatabaseImplement.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -109,6 +110,7 @@ namespace GarmentFactoryDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( name: "Orders"); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs new file mode 100644 index 0000000..817baf3 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs @@ -0,0 +1,214 @@ +// +using System; +using GarmentFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace GarmentFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(GarmentFactoryDatabase))] + [Migration("20240407190354_ClientAddition")] + partial class ClientAddition + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("TextileId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TextileName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Textiles"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("TextileId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("TextileId"); + + b.ToTable("TextileComponents"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("Orders") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Textile"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => + { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("TextileComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") + .WithMany("Components") + .HasForeignKey("TextileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Textile"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("TextileComponents"); + }); + + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs new file mode 100644 index 0000000..9931a8a --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GarmentFactoryDatabaseImplement.Migrations +{ + /// + public partial class ClientAddition : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ClientId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ClientId", + table: "Orders"); + } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs index 73aa3d1..5e471ac 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs @@ -22,6 +22,31 @@ namespace GarmentFactoryDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => { b.Property("Id") @@ -50,6 +75,9 @@ namespace GarmentFactoryDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("ClientId") + .HasColumnType("int"); + b.Property("Count") .HasColumnType("int"); @@ -70,6 +98,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("TextileId"); b.ToTable("Orders"); @@ -123,12 +153,20 @@ namespace GarmentFactoryDatabaseImplement.Migrations modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => { + b.HasOne("GarmentFactoryDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") .WithMany("Orders") .HasForeignKey("TextileId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Textile"); }); @@ -151,6 +189,11 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Textile"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => { b.Navigation("TextileComponents"); diff --git a/GarmentFactory/GarmentFactoryRestApi/Controllers/ClientController.cs b/GarmentFactory/GarmentFactoryRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..7313748 --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/Controllers/ClientController.cs @@ -0,0 +1,69 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace GarmentFactoryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + public ClientController(IClientLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Login error"); + throw; + } + } + + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Registration error"); + throw; + } + } + + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Update data error"); + throw; + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryRestApi/Controllers/MainController.cs b/GarmentFactory/GarmentFactoryRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..6a7ebfd --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/Controllers/MainController.cs @@ -0,0 +1,83 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace GarmentFactoryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly ITextileLogic _textile; + public MainController(ILogger logger, IOrderLogic order, ITextileLogic textile) + { + _logger = logger; + _order = order; + _textile = textile; + } + [HttpGet] + public List? GetTextileList() + { + try + { + return _textile.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка изделия"); + throw; + } + } + [HttpGet] + public TextileViewModel? GetTextile(int textileId) + { + try + { + return _textile.ReadElement(new TextileSearchModel + { + Id = textileId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения изделия по id={Id}", textileId); + throw; + } + } + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return _order.ReadList(new OrderSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиентаid ={ Id}", clientId); + throw; + } + } + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + _order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + + } +} diff --git a/GarmentFactory/GarmentFactoryRestApi/GarmentFactoryRestApi.csproj b/GarmentFactory/GarmentFactoryRestApi/GarmentFactoryRestApi.csproj new file mode 100644 index 0000000..6d1545f --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/GarmentFactoryRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/GarmentFactory/GarmentFactoryRestApi/Program.cs b/GarmentFactory/GarmentFactoryRestApi/Program.cs new file mode 100644 index 0000000..c42e937 --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/Program.cs @@ -0,0 +1,41 @@ +using GarmentFactoryBusinessLogic.BusinessLogics; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; +var builder = WebApplication.CreateBuilder(args); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at +https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "GarmentFactoryRestApi", + Version + = "v1" + }); +}); +var app = builder.Build(); +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "GarmentFactoryRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); + diff --git a/GarmentFactory/GarmentFactoryRestApi/Properties/launchSettings.json b/GarmentFactory/GarmentFactoryRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..7fbaaea --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14977", + "sslPort": 44310 + } + }, + "profiles": { + "GarmentFactoryRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7285;http://localhost:5205", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryRestApi/appsettings.Development.json b/GarmentFactory/GarmentFactoryRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/GarmentFactory/GarmentFactoryRestApi/appsettings.json b/GarmentFactory/GarmentFactoryRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/GarmentFactory/GarmentFactoryRestApi/log4net.config b/GarmentFactory/GarmentFactoryRestApi/log4net.config new file mode 100644 index 0000000..b8c39ce --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file