Giter VIP home page Giter VIP logo

exchange-rate-notifier's Introduction

Exchange rate notifier

Small service for getting updates of current USD to UAH rate.

Features

  • service automatically fetches current USD-UAH rate from Monobank API
  • service automatically sends regular updates to all subscribers every day
  • get current rate using GET /rate
  • subscribe any email using POST /subscribe
  • send manual updated for all subscribed emails using POST /sendEmails

Setup

Define parameters

Create your .env file in the project root folder to specify SMTP and database parameters. You can use the following template:

# SMTP authorization parameters
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=<your google email>
SMTP_PASS=<your password>

# Database source parameters
DB_HOST=localhost # ignored by docker compose!
DB_PORT=5432
DB_USER=user
DB_PASSWORD=password
DB_NAME=emaildb

A comprehensive guide how to set up google credentials to use in apps: link

Build and run

You can use following commands to get the service up and running:

docker compose build
docker compose run

You can do this manually by running go run . but make sure to change default database parameters and have PostgreSQL Server running locally or remotely.

How it works

Application consists of three modules: database for connecting to database and to add and get subscription data, mailsender for working with SMTP to send current rate over email, and ratefetcher to fetch current rate from open API.

First, database connection is initialized and two background processes are started using goroutines for 1. automatic fetching of current rate, 2. automatic email sends to all subscribed emails.

Current rate is automatically fetched from remote API using HTTPS. It is done in reasonable periods of time so remote API is not overwhelmed. Rate value is then cached in memory on each update. Current rate can be fetched from /rate.

Email updates can also be manually sent from /sendEmails and it does not conflict with automatic updates. New email can be subscribed to updates using /subscribe, if email is invalid or it is already subscribed, HTTP status 400 is returned. Email unique contraint is checked by database.

Service uses PostgreSQL for storing subscribers data (in this case only email address). Docker Compose is set up to run database on the separate container but app can use any local or remote database for storing data. Database schema migration is relatively small and is done on each service restart from the service itself.

exchange-rate-notifier's People

Contributors

o-klepatskyi 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.