2024-04-27 22:46:09 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ComputerShopContracts.SearchModels;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class RequestController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IRequestLogic _logic;
|
|
|
|
|
|
|
|
|
|
public RequestController(IRequestLogic logic, ILogger<RequestController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
2024-04-28 21:00:55 +04:00
|
|
|
|
|
|
|
|
|
|
2024-04-27 22:46:09 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public RequestViewModel? GetRequest(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new RequestSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-28 21:00:55 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение заявок по id пользователя (полный список, кот. будет выводиться)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<RequestViewModel>? GetRequests(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadList(new RequestSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-04-27 22:46:09 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateRequest(RequestBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-28 21:00:55 +04:00
|
|
|
|
|
2024-04-30 22:44:30 +04:00
|
|
|
|
//параметры для удобного использования в swagger, потом скорее всего будет передаваться RequestBindingModel model
|
2024-04-28 21:00:55 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void ConnectRequestAssembly(int requestId, int assemblyId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-04-30 22:44:30 +04:00
|
|
|
|
_logic.ConnectRequestAssembly(new RequestBindingModel { Id = requestId, AssemblyId = assemblyId });
|
2024-04-28 21:00:55 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка связывания заявки со сборкой");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-04-27 22:46:09 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateRequest(RequestBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-28 21:00:55 +04:00
|
|
|
|
|
2024-04-27 22:46:09 +04:00
|
|
|
|
[HttpDelete]
|
|
|
|
|
public void DeleteRequest(RequestBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|