From cb2210f479972373980d3e1d35e3b015b666ac92 Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Sat, 27 Apr 2024 17:12:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D1=8F=D1=82=D1=8C=20restapi=20=D0=B8?= =?UTF-8?q?=20implementerApp.=20=20=D0=94=D0=9E=20=D0=9C=D0=98=D0=93=D0=A0?= =?UTF-8?q?=D0=90=D0=A6=D0=98=D0=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputerShopImplementerApp.csproj | 6 ++- .../Models/ErrorViewModel.cs | 9 +++++ ComputerShopImplementerApp/appsettings.json | 3 +- .../ComputerShopRestApi.csproj | 6 +++ .../Controllers/UserController.cs | 40 +++++++++++++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 ComputerShopImplementerApp/Models/ErrorViewModel.cs create mode 100644 ComputerShopRestApi/Controllers/UserController.cs diff --git a/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj b/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj index 2c33b1c..ea3630b 100644 --- a/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj +++ b/ComputerShopImplementerApp/ComputerShopImplementerApp.csproj @@ -7,7 +7,11 @@ - + + + + + diff --git a/ComputerShopImplementerApp/Models/ErrorViewModel.cs b/ComputerShopImplementerApp/Models/ErrorViewModel.cs new file mode 100644 index 0000000..4ee0f60 --- /dev/null +++ b/ComputerShopImplementerApp/Models/ErrorViewModel.cs @@ -0,0 +1,9 @@ +namespace ComputerShopImplementerApp.Models +{ + public class ErrorViewModel + { + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} diff --git a/ComputerShopImplementerApp/appsettings.json b/ComputerShopImplementerApp/appsettings.json index 10f68b8..91026f2 100644 --- a/ComputerShopImplementerApp/appsettings.json +++ b/ComputerShopImplementerApp/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "IpAddress": "http://localhost:5055" } diff --git a/ComputerShopRestApi/ComputerShopRestApi.csproj b/ComputerShopRestApi/ComputerShopRestApi.csproj index 2c33b1c..20cc73d 100644 --- a/ComputerShopRestApi/ComputerShopRestApi.csproj +++ b/ComputerShopRestApi/ComputerShopRestApi.csproj @@ -10,4 +10,10 @@ + + + + + + diff --git a/ComputerShopRestApi/Controllers/UserController.cs b/ComputerShopRestApi/Controllers/UserController.cs new file mode 100644 index 0000000..4de7c31 --- /dev/null +++ b/ComputerShopRestApi/Controllers/UserController.cs @@ -0,0 +1,40 @@ +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class UserController : Controller + { + private readonly ILogger _logger; + private readonly IUserLogic _logic; + + public UserController(IUserLogic logic, ILogger logger) + { + _logic = logic; + _logger = logger; + } + + [HttpGet] + public UserViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new UserSearchModel + { + Login = login, + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + } +}