add ImplementerController

This commit is contained in:
ShabOl 2024-04-16 19:54:51 +04:00
parent 6700d24634
commit 3a5157069b
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,108 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.BusinessLogicsContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace AutoWorkshopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ImplementerController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IImplementerLogic _logic;
public ImplementerController(IOrderLogic Order, IImplementerLogic Logic, ILogger<ImplementerController> Logger)
{
_logger = Logger;
_order = Order;
_logic = Logic;
}
[HttpGet]
public ImplementerViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ImplementerSearchModel
{
ImplementerFIO = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка авторизации сотрудника");
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetNewOrders()
{
try
{
return _order.ReadList(new OrderSearchModel
{
Status = OrderStatus.Accepted
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения новых заказов");
throw;
}
}
[HttpGet]
public OrderViewModel? GetImplementerOrder(int implementerId)
{
try
{
return _order.ReadElement(new OrderSearchModel
{
ImplementerId = implementerId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
throw;
}
}
[HttpPost]
public void TakeOrderInWork(OrderBindingModel Model)
{
try
{
_order.TakeOrderInWork(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", Model.Id);
throw;
}
}
[HttpPost]
public void FinishOrder(OrderBindingModel Model)
{
try
{
_order.FinishOrder(Model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", Model.Id);
throw;
}
}
}
}

View File

@ -1,5 +1,6 @@
using AutoWorkshopBusinessLogic.BusinessLogics;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.BusinessLogicsContracts;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
@ -12,9 +13,13 @@ Builder.Logging.AddLog4Net("log4net.config");
Builder.Services.AddTransient<IClientStorage, ClientStorage>();
Builder.Services.AddTransient<IOrderStorage, OrderStorage>();
Builder.Services.AddTransient<IRepairStorage, RepairStorage>();
Builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
Builder.Services.AddTransient<IOrderLogic, OrderLogic>();
Builder.Services.AddTransient<IClientLogic, ClientLogic>();
Builder.Services.AddTransient<IRepairLogic, RepairLogic>();
Builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
Builder.Services.AddControllers();
Builder.Services.AddEndpointsApiExplorer();