PIbd-23_Vrazhkin_S_A_Furnit.../FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ClientController.cs

86 lines
2.4 KiB
C#
Raw Permalink Normal View History

2024-04-29 18:16:15 +04:00
using FurnitureAssemblyContracts.BindingModels;
2024-05-14 11:30:42 +04:00
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
2024-04-29 18:16:15 +04:00
using FurnitureAssemblyContracts.BusinessLogicsContracts;
using FurnitureAssemblyContracts.SearchModels;
using FurnitureAssemblyContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace FurnitureAssemblyRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
2024-05-14 11:30:42 +04:00
private readonly IMessageInfoLogic _mailLogic;
2024-04-29 18:16:15 +04:00
2024-05-14 11:30:42 +04:00
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
2024-04-29 18:16:15 +04:00
{
_logger = logger;
_logic = logic;
2024-05-14 11:30:42 +04:00
_mailLogic = mailLogic;
2024-04-29 18:16:15 +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-14 11:30:42 +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-04-29 18:16:15 +04:00
}
}