diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index c88f4e0..04876d9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -15,12 +15,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopFileImplement", "BlackcmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{63C0A1A4-FA76-4F7C-8144-A33085F7DF08}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{07550D11-E516-44E1-88A4-5B21E3EE72CC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDatabaseImplement", "BlacksmithWorkshopDatabaseImplement\BlacksmithWorkshopDatabaseImplement.csproj", "{07550D11-E516-44E1-88A4-5B21E3EE72CC}" ProjectSection(ProjectDependencies) = postProject {40A50297-20F6-4F73-834D-0902F6F7965B} = {40A50297-20F6-4F73-834D-0902F6F7965B} {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} = {96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopRestApi", "BlacksmithWorkshopRestApi\BlacksmithWorkshopRestApi.csproj", "{99EB4314-98EC-44D5-BE69-AD066C4018D3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,10 @@ Global {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Debug|Any CPU.Build.0 = Debug|Any CPU {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {07550D11-E516-44E1-88A4-5B21E3EE72CC}.Release|Any CPU.Build.0 = Release|Any CPU + {99EB4314-98EC-44D5-BE69-AD066C4018D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99EB4314-98EC-44D5-BE69-AD066C4018D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99EB4314-98EC-44D5-BE69-AD066C4018D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99EB4314-98EC-44D5-BE69-AD066C4018D3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj new file mode 100644 index 0000000..37fcea7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj @@ -0,0 +1,35 @@ + + + + net8.0 + enable + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ClientController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..1bd7fcd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ClientController.cs @@ -0,0 +1,70 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopRestApi.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/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/MainController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..356b044 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/MainController.cs @@ -0,0 +1,87 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IManufactureLogic _manufacture; + public MainController(ILogger logger, IOrderLogic order, IManufactureLogic manufacture) + { + _logger = logger; + _order = order; + _manufacture = manufacture; + } + [HttpGet] + public List? GetManufactureList() + { + try + { + return _manufacture.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка кузнечных изделий"); + throw; + } + } + [HttpGet] + public ManufactureViewModel? GetManufacture(int manufactureId) + { + try + { + return _manufacture.ReadElement(new ManufactureSearchModel + { + Id = manufactureId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения кузнечного изделия по id={Id}", manufactureId); + 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/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Program.cs new file mode 100644 index 0000000..c977bb3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Program.cs @@ -0,0 +1,54 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopDatabaseImplement.Implements; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; + +namespace BlacksmithWorkshopRestApi +{ + internal class Program + { + private static void Main(string[] args) + { + 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 = "BlacksmithWorkshopRestApi", + 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", + "BlacksmithWorkshopRestApi v1")); + } + app.UseHttpsRedirection(); + app.UseAuthorization(); + app.MapControllers(); + app.Run(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Properties/launchSettings.json b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..420bcb7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:27506", + "sslPort": 44307 + } + }, + "profiles": { + "BlacksmithWorkshopShopRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7130;http://localhost:5189", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.Development.json b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.Development.json new file mode 100644 index 0000000..6ea7671 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.json b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.json new file mode 100644 index 0000000..9c3a5de --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/log4net.config b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/log4net.config new file mode 100644 index 0000000..26f20ea --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file