Giter Site home page Giter Site logo

currency-exchange-rate's Introduction

Currency Exchange API

Overview

This project provides a simple and efficient API for querying currency exchange rates and performing currency conversions. The API is designed to be easy to use, with straightforward endpoints for retrieving exchange rates and converting currency values.

Features

  • Retrieve currencies
  • Register currencies
  • Retrieve currency by name
  • Retrieve currency by ID
  • Ensure test coverage reaches 80% to guarantee robustness and reliability (Sonar).

Architecture

Hexagonal Architecture

The Hexagonal Architecture is a software design model that promotes the isolation of domain logic, located in the inner (business core), from external factors. Communication with domain logic occurs through ports and adapters, ensuring a clear separation between the internal and external parts of the application.

Components of Hexagonal Architecture:

  1. Application Layer:

    • Interface through which users and other programs interact with the application.
    • Includes elements such as user interfaces, RESTful controllers, and JSON serialization libraries.
    • Responsible for exposing the entry point in the application and orchestrating the execution of domain logic.
  2. Domain Layer:

    • Contains the code that implements the business logic, serving as the core of the application.
    • Isolated from application and infrastructure parts.
    • Includes interfaces that define the API for communication with external parts, such as a database.
  3. Infrastructure Layer:

    • Contains all the resources necessary for the application to function.
    • Includes database configuration, Spring configuration, and implementations of infrastructure-dependent interfaces from the domain layer.

hexagonal_architecture

Dependency Inversion in Repository Layer

In the infrastructure layer, we implement the principle of Dependency Inversion in the repository layer. This is achieved by creating an interface in the domain and a corresponding implementation in the infrastructure layer. This approach makes our domain service depend on abstractions, not specific implementations, making the code more flexible and adaptable to changes.

Installation

To install the dependencies required for this project, use the following command:

pip install -r requirements.txt

Usage

Step 1: Start MySQL Database

  • Navigate to the docker-compose directory:

    cd docker-compose
  • Start the MySQL database using Docker Compose:

    docker-compose up -d

Step 2: Run the Application

  • Navigate back to the project root directory:

    python src/Application.py

Run tests

  • To run the tests with coverage
  pytest --cov=src
  • To generate test coverage report with html
  pytest --cov=src --cov-report=html

Retrieve Exchange Rates

GET /exchange-rates

This endpoint returns the latest exchange rates between different currencies.

Convert Currency

GET /convert?from={source_currency}&to={target_currency}&amount={amount}

This endpoint converts a specified amount from one currency to another based on the provided exchange rates.

Rate Limiting

To prevent abuse, this API implements rate limiting. Each user is allowed a certain number of requests within a specified time period. If the rate limit is exceeded, subsequent requests will be rejected until the rate limit period resets.

Example

Retrieve exchange rates:

GET /exchange-rates

Response:

{
  "USD": 1.0,
  "EUR": 0.87,
  "GBP": 0.75,
  ...
}

Convert currency:

GET /convert?from=USD&to=EUR&amount=100

Response:

{
  "from": "USD",
  "to": "EUR",
  "amount": 100,
  "converted_amount": 87
}

Contribution

Contributions to this project are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

currency-exchange-rate's People

Contributors

murilohenzo avatar rhamandalima avatar luizreboucas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.