diff --git a/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln b/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln index d4c4c3c..bf0ac03 100644 --- a/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln +++ b/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantView", "..\MotorP EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantFileImplement", "..\MotorPlantFileImplement\MotorPlantFileImplement.csproj", "{44BB8347-D6F7-4AD3-BC7D-E565CA02E0F8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantDatabaseImplement", "MotorPlantDatabaseImplement\MotorPlantDatabaseImplement.csproj", "{4E5A0E78-08F9-4807-866C-4C7D50693C96}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantDatabaseImplement", "MotorPlantDatabaseImplement\MotorPlantDatabaseImplement.csproj", "{4E5A0E78-08F9-4807-866C-4C7D50693C96}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantRestApi", "MotorPlantRestApi\MotorPlantRestApi.csproj", "{29E5B36D-7602-4EE5-96BB-A43FF9A49780}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {4E5A0E78-08F9-4807-866C-4C7D50693C96}.Debug|Any CPU.Build.0 = Debug|Any CPU {4E5A0E78-08F9-4807-866C-4C7D50693C96}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E5A0E78-08F9-4807-866C-4C7D50693C96}.Release|Any CPU.Build.0 = Release|Any CPU + {29E5B36D-7602-4EE5-96BB-A43FF9A49780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {29E5B36D-7602-4EE5-96BB-A43FF9A49780}.Debug|Any CPU.Build.0 = Debug|Any CPU + {29E5B36D-7602-4EE5-96BB-A43FF9A49780}.Release|Any CPU.ActiveCfg = Release|Any CPU + {29E5B36D-7602-4EE5-96BB-A43FF9A49780}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/ClientController.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..a876f14 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/ClientController.cs @@ -0,0 +1,64 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +namespace MotorPlantRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public ClientController(IClientLogic logic, ILogger + logger) + { + _logger = logger; + _logic = logic; + } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} \ No newline at end of file diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/MainController.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..8333c60 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Controllers/MainController.cs @@ -0,0 +1,85 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using Microsoft.AspNetCore.Mvc; +using MotorPlantContracts.VeiwModels; + +namespace MotorPlantRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IEngineLogic _Engine; + public MainController(ILogger logger, IOrderLogic order, + IEngineLogic Engine) + { + _logger = logger; + _order = order; + _Engine = Engine; + } + [HttpGet] + public List? GetEngineList() + { + try + { + return _Engine.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка мороженного"); + throw; + } + } + [HttpGet] + public EngineViewModel? GetEngine(int EngineId) + { + try + { + return _Engine.ReadElement(new EngineSearchModel + { + Id = + EngineId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", + EngineId); + throw; + } + } + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return _order.ReadList(new OrderSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId); + throw; + } + } + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + _order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.csproj b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.csproj new file mode 100644 index 0000000..f29f326 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + true + + + + + + + + + + + + + + diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.http b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.http new file mode 100644 index 0000000..20cf1fa --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/MotorPlantRestApi.http @@ -0,0 +1,6 @@ +@MotorPlantRestApi_HostAddress = http://localhost:5167 + +GET {{MotorPlantRestApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Program.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Program.cs new file mode 100644 index 0000000..79090cd --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Program.cs @@ -0,0 +1,43 @@ +using MotorPlantBusinessLogic.BusinessLogic; +using MotorPlantBusinessLogic.BusinessLogics; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.StoragesContracts; +using MotorPlantDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at +https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "EngineCompanyRestApi", + Version + = "v1" + }); +}); +var app = builder.Build(); +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "EngineCompanyRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Properties/launchSettings.json b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..c4dc355 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59420", + "sslPort": 44364 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5167", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7267;http://localhost:5167", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.Development.json b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.json b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/log4net.config b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/log4net.config new file mode 100644 index 0000000..3f1bf87 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MotorPlantContracts/SearchModels/OrderSearchModel.cs b/MotorPlantContracts/SearchModels/OrderSearchModel.cs index f185c8f..6349f7c 100644 --- a/MotorPlantContracts/SearchModels/OrderSearchModel.cs +++ b/MotorPlantContracts/SearchModels/OrderSearchModel.cs @@ -3,6 +3,7 @@ public class OrderSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } }