diff --git a/Confectionery.sln b/Confectionery.sln index cb0512c..85836ce 100644 --- a/Confectionery.sln +++ b/Confectionery.sln @@ -15,7 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryFileImplement", "ConfectionaryFileImplement\ConfectioneryFileImplement.csproj", "{47A2EA59-4443-487E-85F4-AC49C04B7211}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryDatabaseImplement", "ConfectioneryDatabaseImplement\ConfectioneryDatabaseImplement.csproj", "{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDatabaseImplement", "ConfectioneryDatabaseImplement\ConfectioneryDatabaseImplement.csproj", "{2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryRestApi", "ConfectioneryRestApi\ConfectioneryRestApi.csproj", "{044CCE68-E866-4957-88D2-4A4D97634808}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryClientApp", "ConfectioneryClientApp\ConfectioneryClientApp.csproj", "{3D0CAD8C-7002-453B-9588-7D78B4B72B7B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +55,14 @@ Global {2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BB59FBD-AA9F-4005-8B0B-6E5176EED6A1}.Release|Any CPU.Build.0 = Release|Any CPU + {044CCE68-E866-4957-88D2-4A4D97634808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {044CCE68-E866-4957-88D2-4A4D97634808}.Debug|Any CPU.Build.0 = Debug|Any CPU + {044CCE68-E866-4957-88D2-4A4D97634808}.Release|Any CPU.ActiveCfg = Release|Any CPU + {044CCE68-E866-4957-88D2-4A4D97634808}.Release|Any CPU.Build.0 = Release|Any CPU + {3D0CAD8C-7002-453B-9588-7D78B4B72B7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D0CAD8C-7002-453B-9588-7D78B4B72B7B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D0CAD8C-7002-453B-9588-7D78B4B72B7B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D0CAD8C-7002-453B-9588-7D78B4B72B7B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ConfectioneryRestApi/ConfectioneryRestApi.csproj b/ConfectioneryRestApi/ConfectioneryRestApi.csproj new file mode 100644 index 0000000..27f8d5b --- /dev/null +++ b/ConfectioneryRestApi/ConfectioneryRestApi.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + Always + + + + diff --git a/ConfectioneryRestApi/Controllers/ClientController.cs b/ConfectioneryRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..6e165ca --- /dev/null +++ b/ConfectioneryRestApi/Controllers/ClientController.cs @@ -0,0 +1,70 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace ConfectioneryRestApi.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; + } + } + } +} diff --git a/ConfectioneryRestApi/Controllers/HomeController.cs b/ConfectioneryRestApi/Controllers/HomeController.cs new file mode 100644 index 0000000..d9f0bae --- /dev/null +++ b/ConfectioneryRestApi/Controllers/HomeController.cs @@ -0,0 +1,82 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace ConfectioneryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IPastryLogic _Pastry; + + public MainController(ILogger logger, IOrderLogic order, IPastryLogic Pastry) + { + _logger = logger; + _order = order; + _Pastry = Pastry; + } + + [HttpGet] + public List? GetPastryList() + { + try + { + return _Pastry.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка изделий"); + throw; + } + } + + [HttpGet] + public PastryViewModel? GetPastry(int PastryId) + { + try + { + return _Pastry.ReadElement(new PastrySearchModel { Id = PastryId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения изделия по id={Id}", PastryId); + 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/ConfectioneryRestApi/Program.cs b/ConfectioneryRestApi/Program.cs new file mode 100644 index 0000000..da7b812 --- /dev/null +++ b/ConfectioneryRestApi/Program.cs @@ -0,0 +1,44 @@ +using ConfectioneryBusinessLogic; +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryDatabaseImplement.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 = "ConfectoneryRestApi", + 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", + "ConfectoneryRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/ConfectioneryRestApi/Properties/launchSettings.json b/ConfectioneryRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..07783b2 --- /dev/null +++ b/ConfectioneryRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:29422", + "sslPort": 44350 + } + }, + "profiles": { + "ConfectioneryRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7146;http://localhost:5010", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/ConfectioneryRestApi/appsettings.Development.json b/ConfectioneryRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ConfectioneryRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ConfectioneryRestApi/appsettings.json b/ConfectioneryRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/ConfectioneryRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/ConfectioneryRestApi/log4net.config b/ConfectioneryRestApi/log4net.config new file mode 100644 index 0000000..43b77f9 --- /dev/null +++ b/ConfectioneryRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file