diff --git a/AutoWorkshop.sln b/AutoWorkshop.sln index 1f3bcf9..9275c1a 100644 --- a/AutoWorkshop.sln +++ b/AutoWorkshop.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoWorkshopFileImplement", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopDatabaseImplement", "AutoWorkshopDatabaseImplement\AutoWorkshopDatabaseImplement.csproj", "{751668F7-01A3-43F0-BDD8-ABB3A8F5A955}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoWorkshopRestApi", "AutoWorkshopRestApi\AutoWorkshopRestApi.csproj", "{15C54F32-1549-4887-BE08-DC6845B0D7ED}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Debug|Any CPU.Build.0 = Debug|Any CPU {751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Release|Any CPU.ActiveCfg = Release|Any CPU {751668F7-01A3-43F0-BDD8-ABB3A8F5A955}.Release|Any CPU.Build.0 = Release|Any CPU + {15C54F32-1549-4887-BE08-DC6845B0D7ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {15C54F32-1549-4887-BE08-DC6845B0D7ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {15C54F32-1549-4887-BE08-DC6845B0D7ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {15C54F32-1549-4887-BE08-DC6845B0D7ED}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AutoWorkshopRestApi/AutoWorkshopRestApi.csproj b/AutoWorkshopRestApi/AutoWorkshopRestApi.csproj new file mode 100644 index 0000000..ae5ab04 --- /dev/null +++ b/AutoWorkshopRestApi/AutoWorkshopRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/AutoWorkshopRestApi/Controllers/ClientController.cs b/AutoWorkshopRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..2b63678 --- /dev/null +++ b/AutoWorkshopRestApi/Controllers/ClientController.cs @@ -0,0 +1,68 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace AutoWorkshopRestApi.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/AutoWorkshopRestApi/Controllers/MainController.cs b/AutoWorkshopRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..efe937f --- /dev/null +++ b/AutoWorkshopRestApi/Controllers/MainController.cs @@ -0,0 +1,86 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace AutoWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IRepairLogic _repair; + + public MainController(ILogger logger, IOrderLogic order, IRepairLogic repair) + { + _logger = logger; + _order = order; + _repair = repair; + } + + [HttpGet] + public List? GetRepairList() + { + try + { + return _repair.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + + [HttpGet] + public RepairViewModel? GetRepair(int repairId) + { + try + { + return _repair.ReadElement(new RepairSearchModel + { + Id = repairId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", repairId); + 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/AutoWorkshopRestApi/Controllers/WeatherForecastController.cs b/AutoWorkshopRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..e184584 --- /dev/null +++ b/AutoWorkshopRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace AutoWorkshopRestApi.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(); + } + } +} diff --git a/AutoWorkshopRestApi/Program.cs b/AutoWorkshopRestApi/Program.cs new file mode 100644 index 0000000..a1a8466 --- /dev/null +++ b/AutoWorkshopRestApi/Program.cs @@ -0,0 +1,39 @@ +using AutoWorkshopBusinessLogic.BusinessLogics; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopDatabaseImplement.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(); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "AutoWorkshopRestApi", + Version = "v1" + }); +}); +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "AutoWorkshopRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/AutoWorkshopRestApi/Properties/launchSettings.json b/AutoWorkshopRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..e818620 --- /dev/null +++ b/AutoWorkshopRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:51095", + "sslPort": 44378 + } + }, + "profiles": { + "AutoWorkshopRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7203;http://localhost:5224", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/AutoWorkshopRestApi/WeatherForecast.cs b/AutoWorkshopRestApi/WeatherForecast.cs new file mode 100644 index 0000000..0e2d387 --- /dev/null +++ b/AutoWorkshopRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace AutoWorkshopRestApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/AutoWorkshopRestApi/appsettings.Development.json b/AutoWorkshopRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/AutoWorkshopRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/AutoWorkshopRestApi/appsettings.json b/AutoWorkshopRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/AutoWorkshopRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/AutoWorkshopRestApi/log4net.config b/AutoWorkshopRestApi/log4net.config new file mode 100644 index 0000000..697cef6 --- /dev/null +++ b/AutoWorkshopRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file