Code Monkey home page Code Monkey logo

backend-go-k-task's Introduction

Description

This repository contains the implementation of a transaction commission calculation task. See the task description below.

Previous iteration with NestJS and TypeScript: https://github.com/LinkPovilas/backend-nest-k-task

Setup

Copy .env.example and rename to .env file. For currency exchange API your need to get an API key from https://exchangerate.host/.

For convenience database is seeded with test data.

./api-test/ dir contains HTTP request example

Running the app

$ docker-compose up -d
$ go run .

Test

# run all tests within the entire code base
$ go test ./...

Task description

Create a RESTful API with an endpoint for transaction commission calculation. The API must use JSON format for requests and responses.

Request (Transaction) examples

1st example

{
  "date": "2021-01-01",
  "amount": "100.00",
  "currency": "EUR",
  "client_id": 42
}

2nd example

{
  "date": "2021-01-01",
  "amount": "200.40",
  "currency": "USD",
  "client_id": 42
}

Response (Commission) example

{
  "amount": "0.05",
  "currency": "EUR"
}

Commission response must always be in Euros. Please use a currency rates API (https://api.exchangerate.host/2021-01-01) for transactions in currency other than Euros.

Commission calculation rules

The lowest commission shall be used if there are multiple rules matching.

Rule #1: Default pricing

By default the price for every transaction is 0.5% but not less than 0.05€.

Rule #2: Client with a discount

Transaction price for the client with ID of 42 is 0.05€ (unless other rules set lower commission).

Rule #3: High turnover discount

Client after reaching transaction turnover of 1000.00€ (per month) gets a discount and transaction commission is 0.03€ for the following transactions.

See below an example in CSV format of rules applied to various transactions.

client_id, date, amount, currency, commission_amount, commission_currency;
42, 2021 - 01 - 02, 2000.0, EUR, 0.05, EUR;
1, 2021 - 01 - 03, 500.0, EUR, 2.5, EUR;
1, 2021 - 01 - 04, 499.0, EUR, 2.5, EUR;
1, 2021 - 01 - 05, 100.0, EUR, 0.5, EUR;
1, 2021 - 01 - 06, 1.0, EUR, 0.03, EUR;
1, 2021 - 02 - 01, 500.0, EUR, 2.5, EUR;

Testing

Please write at least one unit and one integration test.

Remarks

  • You can use any language and any framework. We expect you to show knowledge of your chosen language's ecosystem (frameworks, 3rd party libraries, etc.)
  • Code must follow good practices (such as SOLID, design patterns, etc.) and be easily extendable in case we need to add additional commission calculation rules in the future
  • Please include README.md with instructions how to run your completed task.

backend-go-k-task's People

Contributors

linkpovilas 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.