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"
}
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"
}
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"}
]
A page displaying information from the customer information endpoint.
A page displaying the customer's order history from the orders list endpoint.
git clone [email protected]:chandra-phang/loyalty-program.git
cd loyalty-program
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
brew install postgresql
Using Bundler:
bundle
rails db:create db:migrate db:seed
Start PostgreSQL first
pg_ctl -D /usr/local/var/postgres start
Run the server, accessible through http://localhost:3000/
rails s
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"
}'
rspec
rake customers:calibrate_tier
rake 'customers:archive_tier[:year]'