2024-05-08 08:03:51 +04:00
|
|
|
|
using SecuritySystemContracts.BindingModels;
|
|
|
|
|
using SecuritySystemContracts.BusinessLogicsContracts;
|
|
|
|
|
using SecuritySystemContracts.SearchModels;
|
|
|
|
|
using SecuritySystemContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace SecuritySystemRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
//указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода)
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ClientController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IClientLogic _logic;
|
|
|
|
|
|
2024-05-08 09:27:00 +04:00
|
|
|
|
private readonly IMessageInfoLogic _mailLogic;
|
|
|
|
|
|
|
|
|
|
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
2024-05-08 08:03:51 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
2024-05-08 09:27:00 +04:00
|
|
|
|
_mailLogic = mailLogic;
|
2024-05-08 08:03:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 09:27:00 +04:00
|
|
|
|
|
2024-05-08 08:03:51 +04:00
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-08 09:27:00 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения писем клиента");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-08 08:03:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|