PIbd-22_Chernyshev_Shabunov.../ComputerShopRestApi/Controllers/OrderController.cs

168 lines
3.8 KiB
C#
Raw Normal View History

using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
2024-05-28 19:40:32 +04:00
using ComputerShopBusinessLogic.MailWorker;
2024-04-28 21:00:55 +04:00
using ComputerShopDatabaseImplement.Models;
using ComputerShopDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class OrderController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _logic;
2024-05-28 14:34:16 +04:00
private readonly IReportImplementerLogic _reportLogic;
2024-05-28 19:40:32 +04:00
private readonly AbstractMailWorker _mailWorker;
public OrderController(IOrderLogic logic, ILogger<OrderController> logger, IReportImplementerLogic reportLogic, AbstractMailWorker mailWorker)
{
_logger = logger;
_logic = logic;
2024-05-28 14:34:16 +04:00
_reportLogic = reportLogic;
2024-05-28 19:40:32 +04:00
_mailWorker = mailWorker;
}
[HttpGet]
public OrderViewModel? GetOrder(int id)
{
try
{
return _logic.ReadElement(new OrderSearchModel
{
Id = id
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения заказа");
throw;
}
}
2024-04-28 21:00:55 +04:00
/// <summary>
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<OrderViewModel>? GetOrders(int? userId)
{
try
{
return _logic.ReadList(new OrderSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
2024-05-28 14:34:16 +04:00
[HttpPost]
public void CreateReportToWordFile(ReportBindingModel model)
{
try
{
_reportLogic.SaveReportOrderAssembliesToWordFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
2024-05-28 14:34:16 +04:00
[HttpPost]
public void CreateReportToExcelFile(ReportBindingModel model)
{
try
{
_reportLogic.SaveReportOrderAssembliesToExcelFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
2024-05-28 15:31:13 +04:00
[HttpPost]
public void CreateReportToPDFFile(ReportBindingModel model)
{
try
{
_reportLogic.SaveReportOrdersByDatesToPdfFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
2024-05-28 14:34:16 +04:00
2024-05-28 19:40:32 +04:00
[HttpPost]
public void SendPDFToMail(MailSendInfoBindingModel model)
{
try
{
_mailWorker.MailSendAsync(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отправки письма");
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void UpdateOrder(OrderBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления заказа");
throw;
}
}
[HttpPost]
public void DeleteOrder(OrderBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}
}