Skip to content

vladyslavpavlenko/genesis-api-project

Repository files navigation

Go Report Card

Genesis API Project

This service implements an API for subscribing to exchange rate updates via email (the current implementation focuses on the USD to UAH exchange rate).

API Endpoints

GET /rate

This endpoint returns the current USD to UAH exchange rate using the Coinbase API.

Parameters

No parameters

Response Codes

200: Returns the actual USD to UAH exchange rate.
400: Invalid status value.

POST /subscribe

This endpoint adds an email address to the database and automatically subscribes it to the USD to UAH exchange rate newsletter.

The code includes the ability to subscribe to other rates for future development, but this functionality is not currently used to fulfill the requirements.

Parameters

email string (formData): The email address to be added to the database and the mailing list.

Response Codes

200: The email address is added to the database and subscribed to the mailing list.
409: The email address already exists.

Not mentioned in the task, but arose during the development process:

400: The provided data (such as email address) is invalid.
500: Internal error status.

POST /sendEmails

This endpoint sends the current USD to UAH exchange rate to subscribed email addresses using goroutines.

Parameters

No parameters

Response Codes

200: Emails were sent.

Usage

Clone the repository to your local machine:

git clone https://github.com/vladyslavpavlenko/genesis-api-project.git
cd genesis-api-project

❗️Ensure you have a .env file in the root directory with the necessary environment variables. The .env should look like this:

GMAIL_EMAIL=<GMAIL_EMAIL>
GMAIL_PASSWORD=<GMAIL_APP_PASSWORD>
DB_HOST=<DB_HOST>
DB_PORT=<DB_PORT>
DB_USER=<DB_USER>
DB_PASSWORD=<DB_PASSWORD>
DB_NAME=<DB_NAME>

Makefile

For Unix-like systems, use the following command to build the application binary:

make up_build

For Windows systems, use the following command:

make -f Makefile.windows build_app

To start the Docker containers without forcing a build, run:

make up

To stop the Docker containers, run:

make down

Docker Compose

Alternatively, you can use Docker Compose commands directly:

Start the containers without forcing a build:

docker-compose up -d

Build the application and start the containers:

docker-compose up --build -d

Stop the containers:

docker-compose down

Accessing the Application

The application will be accessible at http://localhost:8080/.

About

API service for currency exchange rate subscriptions, developed as a test task for the Genesis Academy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published