RestApi fix
This commit is contained in:
parent
7fd6c6fb52
commit
b1820879c2
@ -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<ShopController> logger)
|
||||
{
|
||||
return View();
|
||||
_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)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.AddPastry(countPastryForShop.Item1, countPastryForShop.Item2, countPastryForShop.Item3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка пополнения магазина изделиями");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IPastryStorage, PastryStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IPastryLogic, PastryLogic>();
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at
|
||||
|
Loading…
Reference in New Issue
Block a user