diff --git a/SushiBarDatabaseImplement/Models/Order.cs b/SushiBarDatabaseImplement/Models/Order.cs index 967457b..b32f22c 100644 --- a/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBarDatabaseImplement/Models/Order.cs @@ -60,7 +60,7 @@ namespace SushiBarDatabaseImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId + ClientId = ClientId, }; } } diff --git a/SushiBarRestApi/Controllers/ClientController.cs b/SushiBarRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..70791d7 --- /dev/null +++ b/SushiBarRestApi/Controllers/ClientController.cs @@ -0,0 +1,65 @@ +using Microsoft.AspNetCore.Mvc; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; + +namespace SushiBarRestApi.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/SushiBarRestApi/Controllers/MainController.cs b/SushiBarRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..33b9171 --- /dev/null +++ b/SushiBarRestApi/Controllers/MainController.cs @@ -0,0 +1,82 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; + +namespace SushiBarRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly ISushiLogic _sushi; + public MainController(ILogger logger, IOrderLogic order, ISushiLogic sushi) + { + _logger = logger; + _order = order; + _sushi = sushi; + } + [HttpGet] + public List? GetProductList() + { + try + { + return _sushi.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpGet] + public SushiViewModel? GetProduct(int sushiId) + { + try + { + return _sushi.ReadElement(new SushiSearchModel + { + Id = sushiId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", sushiId); + 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; + } + } + } +} \ No newline at end of file diff --git a/SushiBarRestApi/Program.cs b/SushiBarRestApi/Program.cs new file mode 100644 index 0000000..27863ad --- /dev/null +++ b/SushiBarRestApi/Program.cs @@ -0,0 +1,41 @@ +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; +using SushiBarBusinessLogic.BusinessLogic; +using SushiBarBusinessLogic; +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 = "SushiBarRestApi", + 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", + "SushiBarRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); \ No newline at end of file diff --git a/SushiBarRestApi/Properties/launchSettings.json b/SushiBarRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..c491962 --- /dev/null +++ b/SushiBarRestApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:2876", + "sslPort": 44332 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5262", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7106;http://localhost:5262", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SushiBarRestApi/SushiBarRestApi.csproj b/SushiBarRestApi/SushiBarRestApi.csproj new file mode 100644 index 0000000..830945e --- /dev/null +++ b/SushiBarRestApi/SushiBarRestApi.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/SushiBarRestApi/SushiBarRestApi.http b/SushiBarRestApi/SushiBarRestApi.http new file mode 100644 index 0000000..9a80072 --- /dev/null +++ b/SushiBarRestApi/SushiBarRestApi.http @@ -0,0 +1,6 @@ +@SushiBarRestApi_HostAddress = http://localhost:5262 + +GET {{SushiBarRestApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/SushiBarRestApi/WeatherForecast.cs b/SushiBarRestApi/WeatherForecast.cs new file mode 100644 index 0000000..a7f2dfa --- /dev/null +++ b/SushiBarRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace SushiBarRestApi +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/SushiBarRestApi/appsettings.Development.json b/SushiBarRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/SushiBarRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/SushiBarRestApi/appsettings.json b/SushiBarRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/SushiBarRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/SushiBarRestApi/log4net.config b/SushiBarRestApi/log4net.config new file mode 100644 index 0000000..fe2e7b9 --- /dev/null +++ b/SushiBarRestApi/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file