diff --git a/DiningRoom/DiningRoom.sln b/DiningRoom/DiningRoom.sln index 4802270..3490c12 100644 --- a/DiningRoom/DiningRoom.sln +++ b/DiningRoom/DiningRoom.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomDataModels", "Din EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomDatabaseImplement", "DiningRoomDatabaseImplement\DiningRoomDatabaseImplement.csproj", "{348BD2CC-C93D-42E8-A890-FC7807476625}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomBusinessLogic", "DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj", "{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiningRoomBusinessLogic", "DiningRoomBusinessLogic\DiningRoomBusinessLogic.csproj", "{89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiningRoomRestApi", "DiningRoomRestApi\DiningRoomRestApi.csproj", "{BE787325-AB78-45A0-AE64-62E46E64248E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Debug|Any CPU.Build.0 = Debug|Any CPU {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.ActiveCfg = Release|Any CPU {89A8AB71-ADD4-405D-AE0B-03ACB1A1BF24}.Release|Any CPU.Build.0 = Release|Any CPU + {BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE787325-AB78-45A0-AE64-62E46E64248E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE787325-AB78-45A0-AE64-62E46E64248E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs b/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs new file mode 100644 index 0000000..0532dbb --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/CardController.cs @@ -0,0 +1,106 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CardController : Controller + { + private readonly ILogger _logger; + + private readonly ICardLogic _logic; + + public CardController(ICardLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + + [HttpGet] + public CardViewModel? GetCard(int id) + { + try + { + return _logic.ReadElement(new CardSearchModel + { + Id = id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения заказа"); + throw; + } + } + + /// + /// Получение карт по id пользователя (полный список, кот. будет выводиться) + /// + /// + /// + [HttpGet] + public List? GetCards(int userId) + { + try + { + return _logic.ReadList(new CardSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId); + throw; + } + } + + + [HttpPost] + public void CreateCard(CardBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + + + + + [HttpPost] + public void UpdateCard(CardBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления заказа"); + throw; + } + } + + [HttpDelete] + public void DeleteCard(CardBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления заказа"); + throw; + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs b/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs new file mode 100644 index 0000000..72da5df --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/ComponentController.cs @@ -0,0 +1,98 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ComponentController : Controller + { + private readonly ILogger _logger; + private readonly IComponentLogic _componentLogic; + + public ComponentController(IComponentLogic Logic, ILogger Logger) + { + _logger = Logger; + _componentLogic = Logic; + } + + [HttpGet] + public ComponentViewModel? GetComponent(int Id) + { + try + { + return _componentLogic.ReadElement(new ComponentSearchModel + { + Id = Id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта"); + throw; + } + } + + [HttpGet] + public List? GetComponents(int? UserId) + { + try + { + return _componentLogic.ReadList(new ComponentSearchModel + { + UserId = UserId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов пользователя с Id = {Id}", UserId); + throw; + } + } + + [HttpPost] + public void CreateComponent(ComponentBindingModel Model) + { + try + { + _componentLogic.Create(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания продукта"); + throw; + } + } + + [HttpPost] + public void UpdateComponent(ComponentBindingModel Model) + { + try + { + _componentLogic.Update(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления продукта"); + throw; + } + } + + [HttpDelete] + public void DeleteComponent(ComponentBindingModel Model) + { + try + { + _componentLogic.Delete(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления продукта"); + throw; + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs b/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs new file mode 100644 index 0000000..ae8fc75 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/DrinkController.cs @@ -0,0 +1,111 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DrinkController : Controller + { + private readonly ILogger _logger; + private readonly IDrinkLogic _DrinkLogic; + + public DrinkController(IDrinkLogic Logic, ILogger Logger) + { + _logger = Logger; + _DrinkLogic = Logic; + } + + [HttpGet] + public DrinkViewModel? GetDrink(int Id) + { + try + { + return _DrinkLogic.ReadElement(new DrinkSearchModel + { + Id = Id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения напитка"); + throw; + } + } + + [HttpGet] + public List? GetDrinks(int? UserId) + { + try + { + return _DrinkLogic.ReadList(new DrinkSearchModel + { + UserId = UserId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка напитков пользователя с Id = {Id}", UserId); + throw; + } + } + [HttpPost] + public void ConnectCardDrink(int CardId, int DrinkId) + { + try + { + _DrinkLogic.ConnectCardDrink(new DrinkBindingModel { Id = DrinkId, CardId = CardId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка связывания заявки со сборкой"); + throw; + } + } + + [HttpPost] + public void CreateDrink(DrinkBindingModel Model) + { + try + { + _DrinkLogic.Create(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания напитка"); + throw; + } + } + + [HttpPost] + public void UpdateDrink(DrinkBindingModel Model) + { + try + { + _DrinkLogic.Update(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления напитка"); + throw; + } + } + + [HttpDelete] + public void DeleteDrink(DrinkBindingModel Model) + { + try + { + _DrinkLogic.Delete(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления напитка"); + throw; + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs b/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs new file mode 100644 index 0000000..e94e95f --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/OrderController.cs @@ -0,0 +1,101 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using DiningRoomDatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.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; + } + } + + /// + /// Получение заказов по id пользователя (полный список, кот. будет выводиться) + /// + /// + /// + [HttpGet] + public List? GetOrders(int? userId) + { + try + { + return _logic.ReadList(new OrderSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId); + 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; + } + } + + [HttpDelete] + public void DeleteOrder(OrderBindingModel model) + { + try + { + _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления заказа"); + throw; + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs b/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs new file mode 100644 index 0000000..2301599 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/ProductController.cs @@ -0,0 +1,98 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ProductController : Controller + { + private readonly ILogger _logger; + private readonly IProductLogic _productLogic; + + public ProductController(IProductLogic Logic, ILogger Logger) + { + _logger = Logger; + _productLogic = Logic; + } + + [HttpGet] + public ProductViewModel? GetProduct(int Id) + { + try + { + return _productLogic.ReadElement(new ProductSearchModel + { + Id = Id + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения блюда"); + throw; + } + } + + [HttpGet] + public List? GetProducts(int? UserId) + { + try + { + return _productLogic.ReadList(new ProductSearchModel + { + UserId = UserId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка блюд пользователя с Id = {Id}", UserId); + throw; + } + } + + [HttpPost] + public void CreateProduct(ProductBindingModel Model) + { + try + { + _productLogic.Create(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания блюда"); + throw; + } + } + + [HttpPost] + public void UpdateProduct(ProductBindingModel Model) + { + try + { + _productLogic.Update(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления блюда"); + throw; + } + } + + [HttpDelete] + public void DeleteProduct(ProductBindingModel Model) + { + try + { + _productLogic.Delete(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления блюда"); + throw; + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/Controllers/UserController.cs b/DiningRoom/DiningRoomRestApi/Controllers/UserController.cs new file mode 100644 index 0000000..00dc149 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Controllers/UserController.cs @@ -0,0 +1,69 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using DiningRoomDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace DiningRoomRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class UserController : Controller + { + private readonly ILogger _logger; + private readonly IUserLogic _logic; + + public UserController(IUserLogic logic, ILogger logger) + { + _logic = logic; + _logger = logger; + } + + + [HttpGet] + public UserViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new UserSearchModel + { + Login = login, + Password = password, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + 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/DiningRoom/DiningRoomRestApi/DiningRoomRestApi.csproj b/DiningRoom/DiningRoomRestApi/DiningRoomRestApi.csproj new file mode 100644 index 0000000..aedf3de --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/DiningRoomRestApi.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/DiningRoom/DiningRoomRestApi/Program.cs b/DiningRoom/DiningRoomRestApi/Program.cs new file mode 100644 index 0000000..26e4899 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Program.cs @@ -0,0 +1,50 @@ +using DiningRoomBusinessLogic.BusinessLogics; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.StorageContracts; +using DiningRoomDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; + +var Builder = WebApplication.CreateBuilder(args); + + +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + +Builder.Services.AddTransient(); + + +Builder.Services.AddControllers(); +Builder.Services.AddEndpointsApiExplorer(); +Builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "DiningRoomRestApi", + Version = "v1" + }); +}); + +var App = Builder.Build(); + +if (App.Environment.IsDevelopment()) +{ + App.UseSwagger(); + App.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DiningRoomRestApi v1")); +} + +App.UseHttpsRedirection(); +App.UseAuthorization(); +App.MapControllers(); + +App.Run(); diff --git a/DiningRoom/DiningRoomRestApi/Properties/launchSettings.json b/DiningRoom/DiningRoomRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..ffba279 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:38485", + "sslPort": 44318 + } + }, + "profiles": { + "DiningRoomRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7080;http://localhost:5150", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/appsettings.Development.json b/DiningRoom/DiningRoomRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/DiningRoom/DiningRoomRestApi/appsettings.json b/DiningRoom/DiningRoomRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/DiningRoom/DiningRoomRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}