Skip to content

Commit

Permalink
Merge pull request #15 from Brunobento1990/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Brunobento1990 authored May 6, 2024
2 parents 95190fa + 074d9ab commit 8d9cb8e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions OpenAdm.Api/Controllers/PedidoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ public async Task<IActionResult> GetPedidos([FromQuery] int statusPedido)
return await HandleErrorAsync(ex);
}
}

[HttpGet("get")]
public async Task<IActionResult> Get([FromQuery] Guid pedidoId)
{
try
{
var pedido = await _pedidoService.GetAsync(pedidoId);
return Ok(pedido);
}
catch (Exception ex)
{
return await HandleErrorAsync(ex);
}
}
}
6 changes: 3 additions & 3 deletions OpenAdm.Api/Controllers/Pedidos/CreatePedidoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class CreatePedidoController : ControllerBaseApi
private readonly IUsuarioRepository _usuarioRepository;

public CreatePedidoController(
ICreatePedidoService createPedidoService,
ITokenService tokenService,
ICreatePedidoService createPedidoService,
ITokenService tokenService,
IUsuarioRepository usuarioRepository)
{
_createPedidoService = createPedidoService;
Expand All @@ -39,7 +39,7 @@ public async Task<IActionResult> CreatePedido(IList<ItensPedidoModel> itensPedid
}
var result = await _createPedidoService.CreatePedidoAsync(itensPedidoModels, usuario);

return Ok(new { message = "Pedido criado com sucesso!" });
return Ok(new { message = "Pedido criado com sucesso!", pedido = result });
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions OpenAdm.Application/Interfaces/IPedidoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface IPedidoService
{
Task<PaginacaoViewModel<PedidoViewModel>> GetPaginacaoAsync(PaginacaoPedidoDto paginacaoPedidoDto);
Task<List<PedidoViewModel>> GetPedidosUsuarioAsync(int statusPedido, Guid usuarioId);
Task<PedidoViewModel> GetAsync(Guid pedidoId);
}
8 changes: 8 additions & 0 deletions OpenAdm.Application/Services/PedidoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public class PedidoService(
{
private readonly IPedidoRepository _pedidoRepository = pedidoRepository;

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

return new PedidoViewModel().ForModel(pedido);
}

public async Task<PaginacaoViewModel<PedidoViewModel>> GetPaginacaoAsync(PaginacaoPedidoDto paginacaoPedidoDto)
{
var paginacao = await _pedidoRepository.GetPaginacaoPedidoAsync(paginacaoPedidoDto);
Expand Down
4 changes: 3 additions & 1 deletion OpenAdm.Application/Services/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public UsuarioViewModel GetTokenUsuarioViewModel()

var telefone = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "Telefone")?.Value;
var cnpj = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "Cnpj")?.Value;
var cpf = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "Cpf")?.Value;

if (!DateTime.TryParse(dataDeCriacao, out DateTime newDataDeCriacao))
throw new ExceptionApi("token inválido");
Expand All @@ -62,7 +63,8 @@ public UsuarioViewModel GetTokenUsuarioViewModel()
DataDeCriacao = newDataDeCriacao,
DataDeAtualizacao = newDataDeAtualizacao,
Telefone = telefone,
Cnpj = cnpj
Cnpj = cnpj,
Cpf = cpf
};
}
public bool IsFuncionario()
Expand Down

0 comments on commit 8d9cb8e

Please sign in to comment.