using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.ViewModels; using CanteenDatabaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace CanteenRestAPI.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class MainController : Controller { private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly IDishLogic _dish; public MainController(ILogger logger, IOrderLogic order, IDishLogic Dish) { _logger = logger; _order = order; _dish = Dish; } [HttpGet] public List? GetDishList() { try { return _dish.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка блюд"); throw; } } [HttpGet] public DishViewModel? GetDish(int DishId) { try { return _dish.ReadElement(new DishSearchModel { Id = DishId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения блюда по id={Id}", DishId); throw; } } [HttpGet] public List? 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; } } } }