Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Aug 3, 2024
1 parent f6b514f commit 373f72b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Domain.Pkg.Entities;

namespace OpenAdm.Application.Models.EnderecosEntregaPedidos;

public class EnderecoEntregaPedidoViewModel : BaseModel
{
public string Cep { get; set; } = string.Empty;
public decimal Frete { get; set; }
public string Logradouro { get; set; } = string.Empty;
public string NumeroEntrega { get; set; } = string.Empty;
public Guid PedidoId { get; set; }
public string? Complemento { get; set; }
public string Bairro { get; set; } = string.Empty;
public string Localidade { get; set; } = string.Empty;
public string Uf { get; set; } = string.Empty;
public string TipoFrete { get; set; } = string.Empty;

public static EnderecoEntregaPedidoViewModel? ToEntity(EnderecoEntregaPedido? enderecoEntregaPedido)
{
if (enderecoEntregaPedido == null) return null;

return new EnderecoEntregaPedidoViewModel()
{
Bairro = enderecoEntregaPedido.Bairro,
Cep = enderecoEntregaPedido.Cep,
Complemento = enderecoEntregaPedido.Complemento,
DataDeAtualizacao = enderecoEntregaPedido.DataDeAtualizacao,
DataDeCriacao = enderecoEntregaPedido.DataDeCriacao,
Frete = enderecoEntregaPedido.Frete,
Id = enderecoEntregaPedido.Id,
Localidade = enderecoEntregaPedido.Localidade,
Logradouro = enderecoEntregaPedido.Logradouro,
Numero = enderecoEntregaPedido.Numero,
NumeroEntrega = enderecoEntregaPedido.NumeroEntrega,
PedidoId = enderecoEntregaPedido.PedidoId,
TipoFrete = enderecoEntregaPedido.TipoFrete,
Uf = enderecoEntregaPedido.Uf
};
}
}
6 changes: 6 additions & 0 deletions OpenAdm.Application/Models/Pedidos/PedidoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using OpenAdm.Application.Dtos.Bases;
using Domain.Pkg.Entities;
using Domain.Pkg.Enum;
using OpenAdm.Application.Models.EnderecosEntregaPedidos;

namespace OpenAdm.Application.Models.Pedidos;

Expand All @@ -9,13 +10,18 @@ public class PedidoViewModel : BaseViewModel
public StatusPedido StatusPedido { get; set; }
public decimal ValorTotal { get; set; }
public string Usuario { get; set; } = string.Empty;
public IList<ItensPedidoViewModel> ItensPedido { get; set; } = [];
public EnderecoEntregaPedidoViewModel? EnderecoEntrega { get; set; }
public PedidoViewModel ForModel(Pedido entity)
{
Id = entity.Id;
DataDeCriacao = entity.DataDeCriacao;
Numero = entity.Numero;
ValorTotal = entity.ValorTotal;
StatusPedido = entity.StatusPedido;
ItensPedido = entity.ItensPedido.Select(x =>
new ItensPedidoViewModel().ToModel(x)
).ToList();

if (entity.Usuario != null)
Usuario = entity.Usuario.Nome;
Expand Down
17 changes: 11 additions & 6 deletions OpenAdm.Application/Services/PedidoService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Domain.Pkg.Errors;
using Domain.Pkg.Exceptions;
using OpenAdm.Application.Interfaces;
using OpenAdm.Application.Interfaces;
using OpenAdm.Application.Models.EnderecosEntregaPedidos;
using OpenAdm.Application.Models.Pedidos;
using OpenAdm.Domain.Interfaces;
using OpenAdm.Domain.Model;
Expand All @@ -10,17 +9,23 @@
namespace OpenAdm.Application.Services;

public class PedidoService(
IPedidoRepository pedidoRepository)
IPedidoRepository pedidoRepository,
IEnderecoEntregaPedidoRepository enderecoEntregaPedidoRepository)
: IPedidoService
{
private readonly IPedidoRepository _pedidoRepository = pedidoRepository;
private readonly IEnderecoEntregaPedidoRepository _enderecoEntregaPedidoRepository = enderecoEntregaPedidoRepository;

public async Task<PedidoViewModel> GetAsync(Guid pedidoId)
{
var pedido = await _pedidoRepository.GetPedidoByIdAsync(pedidoId)
var pedido = await _pedidoRepository.GetPedidoCompletoByIdAsync(pedidoId)
?? throw new Exception($"Pedido não localizado: {pedidoId}");
var enderecoEntrega = await _enderecoEntregaPedidoRepository.GetEnderecoEntregaPedidoByPedidoIdAsync(pedidoId);

return new PedidoViewModel().ForModel(pedido);
var pedidoViewModel = new PedidoViewModel().ForModel(pedido);
pedidoViewModel.EnderecoEntrega = EnderecoEntregaPedidoViewModel.ToEntity(enderecoEntrega);

return pedidoViewModel;
}

public async Task<PaginacaoViewModel<PedidoViewModel>> GetPaginacaoAsync(PaginacaoPedidoDto paginacaoPedidoDto)
Expand Down

0 comments on commit 373f72b

Please sign in to comment.