2023-03-05 13:38:11 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.SearchModels;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using ConfectioneryDataModels.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-03-05 12:48:11 +04:00
|
|
|
|
|
|
|
|
|
namespace ConfectioneryRestApi.Controllers
|
|
|
|
|
{
|
2023-03-05 13:38:11 +04:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
2023-03-05 12:48:11 +04:00
|
|
|
|
public class ShopController : Controller
|
|
|
|
|
{
|
2023-03-05 13:38:11 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IShopLogic _logic;
|
|
|
|
|
|
|
|
|
|
public ShopController(IShopLogic logic, ILogger<ShopController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ShopViewModel>? 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<ShopSearchModel, IPastryModel, int> countPastryForShop)
|
2023-03-05 12:48:11 +04:00
|
|
|
|
{
|
2023-03-05 13:43:17 +04:00
|
|
|
|
CRUDShop(() => _logic.AddPastry(countPastryForShop.Item1, countPastryForShop.Item2, countPastryForShop.Item3));
|
2023-03-05 12:48:11 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|