Skip to content

candraalim/be_tsel_candra

Repository files navigation

REFERRAL SERVICE

This service intended to

  • generate referral code
  • store referral history
  • claim reward based on referral history

Prerequisites

  • Go 1.13+
  • PostgreSQL 9.4 or later
  • Docker 19.03.4 or later
  • Docker Compose 1.24.1 or later

Library Dependency

|-------------------------------------|--------------------------------------------|
|             DEPENDENCY              |                  DESCRIPTION               |
|-------------------------------------|--------------------------------------------|
| github.com/DATA-DOG/go-sqlmock      | mock sql                                   |
| github.com/jmoiron/sqlx             | sql library                                |
| github.com/labstack/echo/v4         | web framework echo                         |
| github.com/lib/pq                   | postgreSQL driver                          |
| github.com/stretchr/testify         | test toolkit                               |
| golang.org/x/sync                   | handling concurrency                       |
| gopkg.in/go-playground/validator.v9 | validate body request                      |
|-------------------------------------|--------------------------------------------|

Build, Run & Test

Build then Run as binary

Just run

$ make build

and you will find binary with name referral_service. Then configure config.json and run it as usual binary program ./referral_service

Build & Run using docker compose

Just run

$ make run

which will run command

$ docker-compose up

which will build docker image and run postgreSQL using docker compose

Docker

Image Build

$ make docker

which will run command

$ docker build -t referral_service -f Dockerfile .

Test

Get Postman collection at referral_service.postman_collection.json

Use Header Authorization: Basic dGVzdDp0ZXN0MTIz based on configuration auth in config.json

Get Referral Code

curl -L -X GET 'http://localhost:8080/1.0/referral/6280000011/code' \
-H 'Authorization: Basic dGVzdDp0ZXN0MTIz'

Response:
{
    "code": "0000",
    "message": "Success",
    "data": {
        "referralCode": "4C7AE71563"
    }
}

Process Referral

curl -L -X POST 'http://localhost:8080/1.0/referral' \
-H 'Authorization: Basic dGVzdDp0ZXN0MTIz' \
-H 'Content-Type: application/json' \
--data-raw '{
    "code": "4C7AE71563",
    "msisdn": "6282100110011"
}'

Response:
{
    "code": "0000",
    "message": "Success"
}

Get List Referral

curl -L -X GET 'http://localhost:8080/1.0/referral/6280000011' \
-H 'Authorization: Basic dGVzdDp0ZXN0MTIz'

Response:
{
    "code": "0000",
    "message": "Success",
    "data": {
        "list": [
            {
                "msisdn": "6282100110011",
                "referralDate": "2021-08-12",
                "dateTime": 1628750347164
            }
        ],
        "meta": {
            "totalPage": 1,
            "totalRecord": 1,
            "page": 1,
            "size": 1,
            "limit": 10,
            "firstPage": true,
            "lastPage": true
        }
    }
}

Get Referral Reward

curl -L -X GET 'http://localhost:8080/1.0/referral/6280000011/reward' \
-H 'Authorization: Basic dGVzdDp0ZXN0MTIz'

Response:
{
    "code": "0000",
    "message": "Success",
    "data": {
        "totalReferral": 1,
        "reward": "bonus 2 GB"
    }
}

Assumption

  • There is user service already running in place
  • Referral code will be store & generated by this service
  • Referral code generated when user want to get it, not when user success to register
  • Authorization handled by API Gateway
  • Registration process handled by other service, this service always get a legitimate request to process referral

Future improvement

  • Logging to file or ship it for monitoring
  • Configurable length of referral code
  • Use redis to store referral counter per month
  • API CRUD for reward

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published