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();