Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #15

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading