139 lines
2.9 KiB
C#
139 lines
2.9 KiB
C#
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;
|
||
}
|
||
|
||
|
||
[HttpGet]
|
||
public RequestViewModel? GetRequest(int id)
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadElement(new RequestSearchModel
|
||
{
|
||
Id = id
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения заказа");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
/// <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;
|
||
}
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
public void CreateRequest(RequestBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
_logic.Create(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка создания заказа");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
//!!!ПРОВЕРИТЬ
|
||
[HttpPost]
|
||
public void ConnectRequestAssembly(int requestId, int assemblyId)
|
||
{
|
||
try
|
||
{
|
||
_logic.ConnectRequestAssembly(requestId, assemblyId);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка связывания заявки со сборкой");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
public void UpdateRequest(RequestBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
_logic.Update(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка обновления заказа");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
//!!!МБ УДАЛИТЬ
|
||
//[HttpPost]
|
||
//public void AddRequestOrder(int requestId, int orderId)
|
||
//{
|
||
// try
|
||
// {
|
||
// _logic.Update(model);
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// _logger.LogError(ex, "Ошибка обновления заказа");
|
||
// throw;
|
||
// }
|
||
//}
|
||
|
||
|
||
[HttpDelete]
|
||
public void DeleteRequest(RequestBindingModel model)
|
||
{
|
||
try
|
||
{
|
||
_logic.Delete(model);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка удаления заказа");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
//!!!МБ НУЖЕН ОТДЕЛЬНЫЙ МЕТОД ДЛЯ СВЯЗЫВАНИЯ ЗАЯВКИ СО СБОРКОЙ.
|
||
//!!!тогда его надо будет добавлять в IRequestLogic
|
||
}
|
||
}
|