Добавил контроллеры для rest api (проверить)
This commit is contained in:
parent
9b2cb6e071
commit
a141bd778e
@ -41,7 +41,6 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
if (_requestOrders == null)
|
||||
{
|
||||
//!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК)
|
||||
if (_requestOrders == null)
|
||||
{
|
||||
_requestOrders = Orders.ToDictionary(x => x.OrderId, x => (x.Order as IOrderModel));
|
||||
|
80
ComputerShopRestApi/Controllers/OrderController.cs
Normal file
80
ComputerShopRestApi/Controllers/OrderController.cs
Normal file
@ -0,0 +1,80 @@
|
||||
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 OrderController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderLogic _logic;
|
||||
|
||||
public OrderController(IOrderLogic logic, ILogger<OrderController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetOrder(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
//!!!мб HttpPut
|
||||
[HttpDelete]
|
||||
public void DeleteOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
ComputerShopRestApi/Controllers/RequestController.cs
Normal file
82
ComputerShopRestApi/Controllers/RequestController.cs
Normal file
@ -0,0 +1,82 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
//!!!мб HttpPut
|
||||
[HttpDelete]
|
||||
public void DeleteRequest(RequestBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//!!!МБ НУЖЕН ОТДЕЛЬНЫЙ МЕТОД ДЛЯ СВЯЗЫВАНИЯ ЗАЯВКИ СО СБОРКОЙ.
|
||||
//!!!тогда его надо будет добавлять в IRequestLogic
|
||||
}
|
||||
}
|
81
ComputerShopRestApi/Controllers/ShipmentController.cs
Normal file
81
ComputerShopRestApi/Controllers/ShipmentController.cs
Normal file
@ -0,0 +1,81 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
[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;
|
||||
}
|
||||
}
|
||||
//!!!мб HttpPut
|
||||
[HttpDelete]
|
||||
public void DeleteShipment(ShipmentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления партии товаров");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.BindingModels;
|
||||
using ComputerShopContracts.BusinessLogicContracts;
|
||||
using ComputerShopContracts.SearchModels;
|
||||
using ComputerShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -17,6 +18,7 @@ namespace ComputerShopRestApi.Controllers
|
||||
_logic = logic;
|
||||
_logger = logger;
|
||||
}
|
||||
//!!!мб тут нужен пароль
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string login, string password)
|
||||
@ -26,8 +28,7 @@ namespace ComputerShopRestApi.Controllers
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
{
|
||||
Login = login,
|
||||
Email = login,
|
||||
//Password = password
|
||||
Email = login
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -36,5 +37,33 @@ namespace ComputerShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerShopRestApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user