добавлен контроллер

This commit is contained in:
Николай 2023-04-01 22:18:09 +04:00
parent 289697c26d
commit cbbd31f096
2 changed files with 55 additions and 4 deletions

View File

@ -0,0 +1,55 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IUserLogic _logic;
public ClientController(IUserLogic logic, ILogger<ClientController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public UserViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(UserBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
}
}

View File

@ -11,10 +11,6 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />