diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs index a1f1249..99503b1 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs @@ -1,5 +1,6 @@ using BankYouBankruptContracts.BindingModels; using BankYouBankruptContracts.SearchModels; +using BankYouBankruptContracts.StoragesContracts; using BankYouBankruptContracts.ViewModels; using BankYouBankruptDatabaseImplement.Models; using System; @@ -10,7 +11,7 @@ using System.Threading.Tasks; namespace BankYouBankruptDatabaseImplement.Implements { - public class CardStorage + public class CardStorage : ICardStorage { public CardViewModel? Delete(CardBindingModel model) { diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/ClientStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/ClientStorage.cs index 12a5301..2ebe4d0 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/ClientStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/ClientStorage.cs @@ -1,5 +1,6 @@ using BankYouBankruptContracts.BindingModels; using BankYouBankruptContracts.SearchModels; +using BankYouBankruptContracts.StoragesContracts; using BankYouBankruptContracts.ViewModels; using BankYouBankruptDatabaseImplement.Models; using System; @@ -10,7 +11,7 @@ using System.Threading.Tasks; namespace BankYouBankruptDatabaseImplement.Implements { - public class ClientStorage + public class ClientStorage : IClientStorage { public ClientViewModel? Delete(ClientBindingModel model) { diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/BankYouBankruptRestAPI.csproj b/BankYouBankrupt/BankYouBankruptRestAPI/BankYouBankruptRestAPI.csproj index 60bf9ea..bfb0684 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/BankYouBankruptRestAPI.csproj +++ b/BankYouBankrupt/BankYouBankruptRestAPI/BankYouBankruptRestAPI.csproj @@ -7,7 +7,18 @@ - + + + + + + + + + + + + diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ClientController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ClientController.cs new file mode 100644 index 0000000..ee5e01a --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ClientController.cs @@ -0,0 +1,73 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestApi.Controllers +{ + //указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода) + [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/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/MainController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/MainController.cs new file mode 100644 index 0000000..e7492fb --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/MainController.cs @@ -0,0 +1,94 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestApi.Controllers +{ + /// + /// в этом контроллере логика по заказам и изделиям + /// + + //настройка у контроллера, так как снова используем несколько Post и Get запросов + [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/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/WeatherForecastController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/WeatherForecastController.cs deleted file mode 100644 index ff71fc9..0000000 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace BankYouBankruptRestAPI.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(); - } - } -} \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs index d7a851e..8989064 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs @@ -1,11 +1,38 @@ +using BankYouBankruptBusinessLogic.BusinessLogics; +using BankYouBankruptContracts.BusinessLogicsContracts; +using BankYouBankruptContracts.StoragesContracts; +using BankYouBankruptDatabaseImplement.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.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(); + +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "BlacksmithWorkshopRestApi", Version = "v1" }); +}); var app = builder.Build(); @@ -13,7 +40,8 @@ var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlacksmithWorkshopRestApi v1")); } app.UseHttpsRedirection(); @@ -22,4 +50,4 @@ app.UseAuthorization(); app.MapControllers(); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/WeatherForecast.cs b/BankYouBankrupt/BankYouBankruptRestAPI/WeatherForecast.cs deleted file mode 100644 index 75e4d56..0000000 --- a/BankYouBankrupt/BankYouBankruptRestAPI/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace BankYouBankruptRestAPI -{ - 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; } - } -} \ No newline at end of file