From 6775990783798562d2425b67a4d9763e9a936db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Mon, 27 Mar 2023 17:32:45 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D0=B8=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 6 ++ .../BlacksmithWorkshopRestAPI.csproj | 27 ++++++ .../Controllers/ClientController.cs | 65 ++++++++++++++ .../Controllers/MainController.cs | 84 +++++++++++++++++++ .../BlacksmithWorkshopRestAPI/Program.cs | 47 +++++++++++ .../Properties/launchSettings.json | 31 +++++++ .../appsettings.Development.json | 8 ++ .../appsettings.json | 9 ++ .../BlacksmithWorkshopRestAPI/log4net.config | 16 ++++ 9 files changed, 293 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/BlacksmithWorkshopRestAPI.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ClientController.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Properties/launchSettings.json create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.Development.json create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestAPI/log4net.config diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index fc5a9aa..60beb8a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatebaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{2DB15039-1244-4882-BF37-C3FD8C0B7CBB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopRestAPI", "BlacksmithWorkshopRestAPI\BlacksmithWorkshopRestAPI.csproj", "{B873C1C6-126A-4BB9-A7F7-56F36B1CBD0E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {2DB15039-1244-4882-BF37-C3FD8C0B7CBB}.Debug|Any CPU.Build.0 = Debug|Any CPU {2DB15039-1244-4882-BF37-C3FD8C0B7CBB}.Release|Any CPU.ActiveCfg = Release|Any CPU {2DB15039-1244-4882-BF37-C3FD8C0B7CBB}.Release|Any CPU.Build.0 = Release|Any CPU + {B873C1C6-126A-4BB9-A7F7-56F36B1CBD0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B873C1C6-126A-4BB9-A7F7-56F36B1CBD0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B873C1C6-126A-4BB9-A7F7-56F36B1CBD0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B873C1C6-126A-4BB9-A7F7-56F36B1CBD0E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/BlacksmithWorkshopRestAPI.csproj b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/BlacksmithWorkshopRestAPI.csproj new file mode 100644 index 0000000..cd23edf --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/BlacksmithWorkshopRestAPI.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ClientController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ClientController.cs new file mode 100644 index 0000000..9562d34 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ClientController.cs @@ -0,0 +1,65 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestAPI.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/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs new file mode 100644 index 0000000..250c4ae --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs @@ -0,0 +1,84 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestAPI.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IManufactureLogic _manufacture; + public MainController(ILogger logger, IOrderLogic order, IManufactureLogic manufacture) + { + _logger = logger; + _order = order; + _manufacture = manufacture; + } + [HttpGet] + public List? GetManufactureList() + { + try + { + return _manufacture.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpGet] + public ManufactureViewModel? GetManufacture(int manufactureId) + { + try + { + return _manufacture.ReadElement(new ManufactureSearchModel + { + Id = + manufactureId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", + manufactureId); + 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; + } + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs new file mode 100644 index 0000000..dbbaf3f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs @@ -0,0 +1,47 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkShopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.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 = "BlacksmithWorkshopRestApi", 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", "AbstractShopRestApi v1")); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Properties/launchSettings.json b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Properties/launchSettings.json new file mode 100644 index 0000000..54429d8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50387", + "sslPort": 44331 + } + }, + "profiles": { + "BlacksmithWorkshopRestAPI": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7195;http://localhost:5182", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.Development.json b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/log4net.config b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/log4net.config new file mode 100644 index 0000000..51357b2 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file