Добавление контроллера в RestAPI.
This commit is contained in:
parent
d3cffdaa59
commit
4489c8bddb
@ -0,0 +1,110 @@
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using BlacksmithWorkshopContracts.SearchModels;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BlacksmithWorkshopRestApi.Controllers
|
||||
{
|
||||
//настройка у контроллера, так как снова используем несколько Post и Get запросов
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopLogic _logic;
|
||||
|
||||
public ClientController(IShopLogic logic, ILogger<ShopController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ShopViewModel>? GetShopList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ShopViewModel? GetShop(int shopId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ShopSearchModel { Id = shopId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина по id={Id}", shopId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
//создание магазина
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
//изменение магазина
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteShop(ShopBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddManufacture(Tuple<ShopSearchModel, ManufactureBindingModel, int> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.AddManufacture(model.Item1, model.Item2, model.Item3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления изделия в магазин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,10 +14,12 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IManufactureStorage, ManufactureStorage>();
|
||||
builder.Services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IManufactureLogic, ManufactureLogic>();
|
||||
builder.Services.AddTransient<IShopLogic, ShopLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user