From 5f602d4bc6b806fd33db69b69957e342a7925093 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 26 Mar 2023 18:57:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20RestAPI=20=D0=BF=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B5:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB?= =?UTF-8?q?=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ShopController.cs | 111 ++++++++++++++++++ .../FurnitureAssemblyRestApi/Program.cs | 2 + 2 files changed, 113 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs new file mode 100644 index 0000000..9b7db61 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs @@ -0,0 +1,111 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; + +namespace FurnitureAssemblyRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ShopController : Controller + { + private readonly ILogger _logger; + private readonly IShopLogic _shop; + + public ShopController(ILogger logger, IShopLogic shopLogic) + { + _logger = logger; + _shop = shopLogic; + } + + + [HttpGet] + public List? GetShopList() + { + try + { + return _shop.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + + [HttpGet] + public ShopViewModel? GetShop(int shopId) + { + try + { + return _shop.ReadElement(new ShopSearchModel + { + Id = shopId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения магазина по id={Id}", + shopId); + throw; + } + } + + [HttpPost] + public void CreateShop(ShopBindingModel model) + { + try + { + _shop.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания магазина"); + throw; + } + } + + [HttpPost] + public void UpdateShop(ShopBindingModel model) + { + try + { + _shop.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления магазина"); + throw; + } + } + + [HttpPost] + public void DeleteShop(ShopBindingModel model) + { + try + { + _shop.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + [HttpPost] + public void AddFurnituresToShop(Tuple addInfo) + { + try + { + _shop.AddFurniture(addInfo.Item1, addInfo.Item2, addInfo.Item3); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs index 1c84a1c..1a2a0aa 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs @@ -14,8 +14,10 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddControllers();