88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
|
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 IBouquetLogic _bouquet;
|
|||
|
|
|||
|
public MainController(ILogger<MainController> logger, IOrderLogic order, IBouquetLogic bouquet)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_order = order;
|
|||
|
_bouquet = bouquet;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<BouquetViewModel>? GetBouquetList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _bouquet.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error during loading list of bouquets");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public BouquetViewModel? GetBouquet(int bouquetId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _bouquet.ReadElement(new BouquetSearchModel
|
|||
|
{
|
|||
|
Id = bouquetId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error during receiving bouquet with id={Id}", bouquetId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<OrderViewModel>? GetOrders(int clientId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _order.ReadList(new OrderSearchModel
|
|||
|
{
|
|||
|
ClientId = clientId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error during loading list of orders of client with id = {Id}", clientId);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void CreateOrder(OrderBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_order.CreateOrder(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error during creation of order");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|