2024-04-04 18:22:29 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
|
using FlowerShopContracts.BindingModels;
|
|
|
|
|
using FlowerShopContracts.BusinessLogicsContracts;
|
|
|
|
|
using FlowerShopContracts.SearchModels;
|
|
|
|
|
using FlowerShopContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace FlowerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class MainController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IOrderLogic _order;
|
|
|
|
|
private readonly IFlowerLogic _flower;
|
|
|
|
|
public MainController(ILogger<MainController> logger, IOrderLogic order, IFlowerLogic flower)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_order = order;
|
|
|
|
|
_flower = flower;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<FlowerViewModel>? GetFlowerList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _flower.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка цветов");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public FlowerViewModel? GetFlower(int flowerId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _flower.ReadElement(new FlowerSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = flowerId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения цветов по id = {Id}",flowerId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-04-18 19:47:00 +04:00
|
|
|
|
public List<OrderViewModel>? GetOrders(int? clientId)
|
2024-04-04 18:22:29 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-04-18 19:47:00 +04:00
|
|
|
|
return _order.ReadList(clientId != null ? new OrderSearchModel
|
2024-04-04 18:22:29 +04:00
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
2024-04-18 19:47:00 +04:00
|
|
|
|
} : null);
|
2024-04-04 18:22:29 +04:00
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|