This commit is contained in:
Галина Федоренко 2024-04-19 14:12:20 +04:00
parent 719445fe81
commit 9d7b0751c8
3 changed files with 151 additions and 4 deletions

View File

@ -11,10 +11,6 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarpentryWorkshopBusinessLogic\CarpentryWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\CarpentryWorkshopDatabaseImplement\CarpentryWorkshopDatabaseImplement.csproj" />

View File

@ -0,0 +1,69 @@
using CarpentryWorkshopContracts.BindingModels;
using CarpentryWorkshopContracts.BusinessLogicsContracts;
using CarpentryWorkshopContracts.SearchModels;
using CarpentryWorkshopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CarpentryWorkshopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public ClientViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(ClientBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(ClientBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}

View File

@ -0,0 +1,82 @@
using CarpentryWorkshopContracts.BindingModels;
using CarpentryWorkshopContracts.BusinessLogicsContracts;
using CarpentryWorkshopContracts.SearchModels;
using CarpentryWorkshopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace CarpentryWorkshopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IWoodLogic _wood;
public MainController(ILogger<MainController> logger, IOrderLogic order, IWoodLogic wood)
{
_logger = logger;
_order = order;
_wood = wood;
}
[HttpGet]
public List<WoodViewModel>? GetWoodList()
{
try
{
return _wood.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка изделий");
throw;
}
}
[HttpGet]
public WoodViewModel? GetWood(int woodId)
{
try
{
return _wood.ReadElement(new WoodSearchModel { Id = woodId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", woodId);
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetOrders(int clientId)
{
try
{
return _order.ReadList(new OrderSearchModel { ClientId = clientId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_order.CreateOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
}
}