PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantRestApi/Controllers/ClientController.cs
2024-05-04 22:30:27 +04:00

127 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace AircraftPlantRestApi.Controllers
{
/// <summary>
/// Контроллер для работы с клиентами
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Бизнес-логика для клиентов
/// </summary>
private readonly IClientLogic _logic;
/// <summary>
/// Бизнес-логика для писем
/// </summary>
private readonly IMessageInfoLogic _mailLogic;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logic"></param>
/// <param name="logger"></param>
/// <param name="mailLogic"></param>
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
{
_logger = logger;
_logic = logic;
_mailLogic = mailLogic;
}
/// <summary>
/// Вход в систему
/// </summary>
/// <param name="login"></param>
/// <param name="password"></param>
/// <returns></returns>
[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;
}
}
/// <summary>
/// Регистрация
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void Register(ClientBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
/// <summary>
/// Обновление данных
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void UpdateData(ClientBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
/// <summary>
/// Получение списка писем клиента
/// </summary>
/// <param name="clientId"></param>
/// <returns></returns>
[HttpGet]
public List<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения писем клиента");
throw;
}
}
}
}