diff --git a/ComputerShopDatabaseImplement/Models/Request.cs b/ComputerShopDatabaseImplement/Models/Request.cs index e128e32..bcb925c 100644 --- a/ComputerShopDatabaseImplement/Models/Request.cs +++ b/ComputerShopDatabaseImplement/Models/Request.cs @@ -41,7 +41,6 @@ namespace ComputerShopDatabaseImplement.Models { if (_requestOrders == null) { - //!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК) if (_requestOrders == null) { _requestOrders = Orders.ToDictionary(x => x.OrderId, x => (x.Order as IOrderModel)); diff --git a/ComputerShopRestApi/Controllers/OrderController.cs b/ComputerShopRestApi/Controllers/OrderController.cs new file mode 100644 index 0000000..ba9cbb5 --- /dev/null +++ b/ComputerShopRestApi/Controllers/OrderController.cs @@ -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 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; + } + } + } +} diff --git a/ComputerShopRestApi/Controllers/RequestController.cs b/ComputerShopRestApi/Controllers/RequestController.cs new file mode 100644 index 0000000..87d4e41 --- /dev/null +++ b/ComputerShopRestApi/Controllers/RequestController.cs @@ -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 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 + } +} diff --git a/ComputerShopRestApi/Controllers/ShipmentController.cs b/ComputerShopRestApi/Controllers/ShipmentController.cs new file mode 100644 index 0000000..9ba2a89 --- /dev/null +++ b/ComputerShopRestApi/Controllers/ShipmentController.cs @@ -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 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; + } + } + } +} diff --git a/ComputerShopRestApi/Controllers/UserController.cs b/ComputerShopRestApi/Controllers/UserController.cs index 71b8286..9319d6d 100644 --- a/ComputerShopRestApi/Controllers/UserController.cs +++ b/ComputerShopRestApi/Controllers/UserController.cs @@ -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; + } + } } } diff --git a/ComputerShopRestApi/Controllers/WeatherForecastController.cs b/ComputerShopRestApi/Controllers/WeatherForecastController.cs deleted file mode 100644 index d05a5d6..0000000 --- a/ComputerShopRestApi/Controllers/WeatherForecastController.cs +++ /dev/null @@ -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 _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable 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(); - } - } -}