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 logger, IOrderLogic order, IBouquetLogic bouquet) { _logger = logger; _order = order; _bouquet = bouquet; } [HttpGet] public List? 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? 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; } } } }