-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from Brunobento1990/develop
feature criar pedido pelo admin
- Loading branch information
Showing
9 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
OpenAdm.Api/Controllers/Pedidos/CreatePedidoAdmController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenAdm.Api.Attributes; | ||
using OpenAdm.Application.Dtos.Pedidos; | ||
using OpenAdm.Application.Interfaces.Pedidos; | ||
|
||
namespace OpenAdm.Api.Controllers.Pedidos; | ||
|
||
[ApiController] | ||
[Route("pedidos-adm")] | ||
[Autentica] | ||
[AutenticaParceiro] | ||
[IsFuncionario] | ||
public class CreatePedidoAdmController : ControllerBase | ||
{ | ||
private readonly ICreatePedidoAdmService _createPedidoAdmService; | ||
|
||
public CreatePedidoAdmController(ICreatePedidoAdmService createPedidoAdmService) | ||
{ | ||
_createPedidoAdmService = createPedidoAdmService; | ||
} | ||
|
||
[HttpPost("create")] | ||
public async Task<IActionResult> CreatePedido(PedidoAdmCreateDto pedidoAdmCreateDto) | ||
{ | ||
var result = await _createPedidoAdmService.CreateAsync(pedidoAdmCreateDto); | ||
|
||
return Ok(new { result }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using OpenAdm.Domain.Model.Pedidos; | ||
|
||
namespace OpenAdm.Application.Dtos.Pedidos; | ||
|
||
public class PedidoAdmCreateDto | ||
{ | ||
public Guid UsuarioId { get; set; } | ||
public IList<ItemPedidoModel> Itens { get; set; } = []; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
OpenAdm.Application/Interfaces/Pedidos/ICreatePedidoAdmService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using OpenAdm.Application.Dtos.Pedidos; | ||
|
||
namespace OpenAdm.Application.Interfaces.Pedidos; | ||
|
||
public interface ICreatePedidoAdmService | ||
{ | ||
Task<bool> CreateAsync(PedidoAdmCreateDto pedidoAdmCreateDto); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
OpenAdm.Application/Services/Pedidos/CreatePedidoAdmService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using OpenAdm.Application.Dtos.Pedidos; | ||
using OpenAdm.Application.Interfaces; | ||
using OpenAdm.Application.Interfaces.Pedidos; | ||
using OpenAdm.Domain.Entities; | ||
using OpenAdm.Domain.Enuns; | ||
using OpenAdm.Domain.Exceptions; | ||
using OpenAdm.Domain.Interfaces; | ||
|
||
namespace OpenAdm.Application.Services.Pedidos; | ||
|
||
public class CreatePedidoAdmService : ICreatePedidoAdmService | ||
{ | ||
private readonly IPedidoRepository _pedidoRepository; | ||
private readonly IProcessarPedidoService _processarPedidoService; | ||
private readonly IItemTabelaDePrecoRepository _itemTabelaDePrecoRepository; | ||
private readonly IFaturaService _faturaService; | ||
private readonly IUsuarioService _usuarioService; | ||
|
||
public CreatePedidoAdmService( | ||
IPedidoRepository pedidoRepository, | ||
IProcessarPedidoService processarPedidoService, | ||
IItemTabelaDePrecoRepository itemTabelaDePrecoRepository, | ||
IFaturaService faturaService, | ||
IUsuarioService usuarioService) | ||
{ | ||
_pedidoRepository = pedidoRepository; | ||
_processarPedidoService = processarPedidoService; | ||
_itemTabelaDePrecoRepository = itemTabelaDePrecoRepository; | ||
_faturaService = faturaService; | ||
_usuarioService = usuarioService; | ||
} | ||
|
||
public async Task<bool> CreateAsync(PedidoAdmCreateDto pedidoAdmCreateDto) | ||
{ | ||
if (pedidoAdmCreateDto.Itens.Count == 0) | ||
{ | ||
throw new ExceptionApi("Informe os itens do pedido!"); | ||
} | ||
var usuario = await _usuarioService.GetUsuarioByIdValidacaoAsync(id: pedidoAdmCreateDto.UsuarioId); | ||
var date = DateTime.Now; | ||
var pedido = new Pedido(Guid.NewGuid(), date, date, 0, StatusPedido.Aberto, usuario.Id); | ||
|
||
var produtosIds = pedidoAdmCreateDto.Itens.Select(x => x.ProdutoId).ToList(); | ||
var itensTabelaDePreco = await _itemTabelaDePrecoRepository.GetItensTabelaDePrecoByIdProdutosAsync(produtosIds); | ||
|
||
pedido.ProcessarItensPedido(pedidoAdmCreateDto.Itens); | ||
|
||
await _pedidoRepository.AddAsync(pedido); | ||
await _processarPedidoService.ProcessarCreateAsync(pedido.Id); | ||
|
||
|
||
await _faturaService.CriarContasAReceberAsync(new() | ||
{ | ||
DataDoPrimeiroVencimento = DateTime.Now.AddMonths(1), | ||
Desconto = null, | ||
MeioDePagamento = null, | ||
Observacao = $"Pedido: {pedido.Numero}", | ||
PedidoId = pedido.Id, | ||
QuantidadeDeParcelas = 1, | ||
Total = pedido.ValorTotal, | ||
UsuarioId = pedido.UsuarioId, | ||
Tipo = TipoFaturaEnum.A_Receber | ||
}); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters