diff --git a/ConfectioneryRestApi/Controllers/ShopController.cs b/ConfectioneryRestApi/Controllers/ShopController.cs index 6ee41a4..fc2623d 100644 --- a/ConfectioneryRestApi/Controllers/ShopController.cs +++ b/ConfectioneryRestApi/Controllers/ShopController.cs @@ -1,12 +1,73 @@ -using Microsoft.AspNetCore.Mvc; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.AspNetCore.Mvc; namespace ConfectioneryRestApi.Controllers { + [Route("api/[controller]/[action]")] + [ApiController] public class ShopController : Controller { - public IActionResult Index() + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + public ShopController(IShopLogic logic, ILogger logger) { - return View(); + _logger = logger; + _logic = logic; + } + + [HttpGet] + public List? GetShops() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + + [HttpPost] + public void CRUDShop(Action action) + { + try + { + action.Invoke(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка операции CRUD - {operation} с магазином", action.Method.Name); + throw; + } + } + + [HttpPost] + public void UpdateShop(ShopBindingModel model) => CRUDShop(() => _logic.Update(model)); + [HttpPost] + public void CreateShop(ShopBindingModel model) => CRUDShop(() => _logic.Create(model)); + [HttpPost] + public void DeleteShop(ShopBindingModel model) => CRUDShop(() => _logic.Delete(model)); + + [HttpPost] + public void AddPastryInShop(Tuple countPastryForShop) + { + try + { + _logic.AddPastry(countPastryForShop.Item1, countPastryForShop.Item2, countPastryForShop.Item3); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка пополнения магазина изделиями"); + throw; + } } } } diff --git a/ConfectioneryRestApi/Program.cs b/ConfectioneryRestApi/Program.cs index da7b812..d2c513c 100644 --- a/ConfectioneryRestApi/Program.cs +++ b/ConfectioneryRestApi/Program.cs @@ -2,6 +2,7 @@ using ConfectioneryBusinessLogic; using ConfectioneryBusinessLogic.BusinessLogics; using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.StoragesContract; +using ConfectioneryDatabaseImplement; using ConfectioneryDatabaseImplement.Implements; using Microsoft.OpenApi.Models; @@ -13,10 +14,12 @@ 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.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at