ISEbd-21.Gordeev.I.V.SushiB.../SushiBar/SushiBarRestApi/Controllers/ClientController.cs

85 lines
2.6 KiB
C#
Raw Normal View History

2024-05-01 10:50:16 +04:00
using Microsoft.AspNetCore.Mvc;
using SushiBarContracts.BindingModel;
2024-04-25 13:16:23 +04:00
using SushiBarContracts.BusinessLogicsContracts;
2024-05-01 10:50:16 +04:00
using SushiBarContracts.SearchModel;
2024-05-16 18:55:15 +04:00
using SushiBarContracts.SearchModels;
2024-04-25 13:16:23 +04:00
using SushiBarContracts.ViewModels;
2024-05-12 19:04:40 +04:00
2024-04-25 13:16:23 +04:00
namespace SushiBarRestApi.Controllers
{
2024-05-12 19:04:40 +04:00
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
private readonly ILogger _logger;
2024-05-16 18:55:15 +04:00
private readonly IClientLogic _logic;
private readonly IMessageInfoLogic _mailLogic;
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
_logger = logger;
_logic = logic;
2024-05-16 18:55:15 +04:00
_mailLogic = mailLogic;
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpGet]
public ClientViewModel? Login(string login, string password)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpPost]
public void Register(ClientBindingModel model)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
[HttpPost]
public void UpdateData(ClientBindingModel model)
2024-04-25 13:16:23 +04:00
{
2024-05-12 19:04:40 +04:00
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
2024-04-25 13:16:23 +04:00
}
2024-05-16 18:55:15 +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-25 13:16:23 +04:00
}
2024-05-12 19:04:40 +04:00
2024-05-16 18:55:15 +04:00
}
}