diff --git a/FurnitureAssembly/FurnitureAssembly.sln b/FurnitureAssembly/FurnitureAssembly.sln index ff7d6ae..2f0d2b4 100644 --- a/FurnitureAssembly/FurnitureAssembly.sln +++ b/FurnitureAssembly/FurnitureAssembly.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemFileImplement EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDatabaseImplement", "FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj", "{F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyRestApi", "FurnitureAssemblyRestApi\FurnitureAssemblyRestApi.csproj", "{2BA2B5A8-DE7B-4E6F-A84A-04FD7566CE97}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Debug|Any CPU.Build.0 = Debug|Any CPU {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Release|Any CPU.ActiveCfg = Release|Any CPU {F4FAEBEF-1E02-44DE-A13B-27A8C3838D98}.Release|Any CPU.Build.0 = Release|Any CPU + {2BA2B5A8-DE7B-4E6F-A84A-04FD7566CE97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BA2B5A8-DE7B-4E6F-A84A-04FD7566CE97}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BA2B5A8-DE7B-4E6F-A84A-04FD7566CE97}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BA2B5A8-DE7B-4E6F-A84A-04FD7566CE97}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..acf7af8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs @@ -0,0 +1,66 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace FurnitureAssemblyRestApi.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, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MainController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..20116d8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/MainController.cs @@ -0,0 +1,84 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace FurnitureAssemblyRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IFurnitureLogic _furniture; + + public MainController(ILogger logger, IOrderLogic order, IFurnitureLogic furniture) + { + _logger = logger; + _order = order; + _furniture = furniture; + } + [HttpGet] + public List? GetFurnitureList() + { + try + { + return _furniture.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка мебели"); + throw; + } + } + [HttpGet] + public FurnitureViewModel? GetFurniture(int furnitureId) + { + try + { + return _furniture.ReadElement(new FurnitureSearchModel + { + Id = furnitureId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения мебели по id={Id}", + furnitureId); + 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/FurnitureAssembly/FurnitureAssemblyRestApi/FurnitureAssemblyRestApi.csproj b/FurnitureAssembly/FurnitureAssemblyRestApi/FurnitureAssemblyRestApi.csproj new file mode 100644 index 0000000..53f4c87 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/FurnitureAssemblyRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs new file mode 100644 index 0000000..1c84a1c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs @@ -0,0 +1,45 @@ +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyDatabaseImplement.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 = "FurnitureAssemblyRestApi", + 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", + "FurnitureAssemblyRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Properties/launchSettings.json b/FurnitureAssembly/FurnitureAssemblyRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..c39ec1d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:17974", + "sslPort": 44326 + } + }, + "profiles": { + "FurnitureAssemblyRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7078;http://localhost:5078", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.Development.json b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/log4net.config b/FurnitureAssembly/FurnitureAssemblyRestApi/log4net.config new file mode 100644 index 0000000..43b77f9 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file