Code Monkey home page Code Monkey logo

loyalty-program's Introduction

Backend API

Order Endpoint

An endpoint to report a completed order, saving it in the database and recalculating the customer's tier.

POST /api/report-order
{
  "customerId": "123",
  "customerName": "Taro Suzuki",
  "orderId": "T123",
  "totalInCents": 3450,
  "date": "2022-03-04T05:29:59.850Z"
}

Customer Information Endpoint

An endpoint returning information about a customer when given their ID.

GET /api/customer-info/:customerId
{
  "currentTier": "Silver",
  "tierStartDate": "2021-01-01",
  "amountSpentSinceStart": "$100.00",
  "amountToReachNextTier": "$400.00",
  "nextYearDowngradeTier": "Bronze",
  "downgradeDate": "2023-01-01",
  "amountToSpendToMaintainTier": "$0.00"
}

Orders List Endpoint

An endpoint listing the customer's orders since the start of last year.

GET /api/customer-orders/:customerId
[
  {"orderId": "T123", "date": "2022-03-04", "total": "$34.50"},
  {"orderId": "T124", "date": "2022-03-05", "total": "$45.20"}
]

Frontend App

Customer Information Page

A page displaying information from the customer information endpoint.

Order History Page

A page displaying the customer's order history from the orders list endpoint.

Loyalty Program

Install

Clone the repository

git clone [email protected]:chandra-phang/loyalty-program.git
cd loyalty-program

Check your Ruby version

ruby -v

The ouput should start with something like ruby 3.1.2

If not, install the right ruby version using rbenv:

rbenv install 3.1.2

Install PostgreSQL

brew install postgresql

Install dependencies

Using Bundler:

bundle

Initialize the Database

rails db:create db:migrate db:seed

Running the Application

Start PostgreSQL first

pg_ctl -D /usr/local/var/postgres start

Run the server, accessible through http://localhost:3000/

rails s

Curl to Report Completed Order

curl --location 'http://localhost:3000/orders/report' \
--header 'Content-Type: application/json' \
--data '{
    "customerId": "123",
    "customerName": "Taro Suzuki",
    "orderId": "T123",
    "totalInCents": 3450,
    "date": "2022-03-04T05:29:59.850Z"
}'

Running Tests

rspec

Run Tier Calibration Task after the new year has started

rake customers:calibrate_tier

Run Customer Tier Archive after the new year has started

rake 'customers:archive_tier[:year]'

loyalty-program's People

Contributors

chandra-phang 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.