84 lines
1.7 KiB
C#
84 lines
1.7 KiB
C#
|
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<MainController> logger, IOrderLogic order, IDishLogic Dish)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_order = order;
|
|||
|
_dish = Dish;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<DishViewModel>? 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<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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|