Skip to content

Eduardo Lopes - Conclusão do desafio#210

Open
elopes-sv wants to merge 2 commits intoApiki:masterfrom
elopes-sv:eduardo-lopes
Open

Eduardo Lopes - Conclusão do desafio#210
elopes-sv wants to merge 2 commits intoApiki:masterfrom
elopes-sv:eduardo-lopes

Conversation

@elopes-sv
Copy link
Copy Markdown

Contexto

Implementa a API REST de conversão de moedas do desafio.

O que foi feito

  • adiciona o front controller em src/index.php
  • cria ExchangeRequest para representar os dados validados da rota
  • cria ExchangeRequestFactory para validar e extrair /exchange/{amount}/{from}/{to}/{rate}
  • cria ExchangeService para aplicar a regra de conversão e definir o símbolo da moeda
  • cria JsonResponse para centralizar a resposta JSON
  • cria BadRequestException para tratar requisições inválidas com status 400

Como validar

  • subir o servidor: php -S localhost:8000 src/index.php
  • acessar no navegador ou via HTTP:
    • http://localhost:8000/exchange/10/BRL/USD/4.50
  • rodar testes: composer test
  • rodar lint: composer lint

Evidências

Validação manual

image

Testes automatizados

image

Lint

image

@elopes-sv elopes-sv changed the title Eduardo lopes feat(exchange): implementa API de conversão de moedas Apr 6, 2026
@elopes-sv elopes-sv changed the title feat(exchange): implementa API de conversão de moedas Eduardo Lopes - Conclusão do desafio Apr 6, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 374c96b42c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

return [
'valorConvertido' => $request->getAmount() * $request->getRate(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid binary float artifacts in monetary conversion

Using direct float multiplication for valorConvertido can produce visibly wrong monetary values for some decimal inputs (for example, 0.1 * 0.2 yields 0.020000000000000004 in PHP), which hurts API accuracy and can break strict client assertions. Since this endpoint returns currency amounts, the result should be normalized to a defined precision (or computed with decimal-safe arithmetic) before serializing the response.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant