105 lines
2.2 KiB
C#
105 lines
2.2 KiB
C#
using ComputerShopContracts.BindingModels;
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
using ComputerShopContracts.SearchModels;
|
|
using ComputerShopContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ShipmentController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly IShipmentLogic _logic;
|
|
|
|
public ShipmentController(IShipmentLogic logic, ILogger<ShipmentController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
public ShipmentViewModel? GetShipment(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new ShipmentSearchModel
|
|
{
|
|
Id = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения партии товара");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получение партий по id пользователя (полный список, кот. будет выводиться)
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public List<ShipmentViewModel>? GetShipments(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(new ShipmentSearchModel { UserId = userId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
public void CreateShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void UpdateShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpDelete]
|
|
public void DeleteShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|