https://youtu.be/-5DR7Ea8TIg
- Ruby 2.7.5
- Rails 6
- Postgres
- Rspec, Factory-bot, shoulda-matchers
Need to seed the lines by calling rails db:seed
Docker setup
docker-compose build
docker-compose up
- As a train operator
- I can register the account (with name only)
- I get api_key (simple 6 digits key)
- I use api_key to submit a train
- I use api_key to withdraw a train
- I use api_key to check status of a train
- I cannot withdraw a train that is running
- As a customer
- I can register the account (with name only)
- I get api_key (simple 6 digits key)
- I use api_key to submit a package
- I use api_key to check status of a package
- I use api_key to withdraw a package
- I cannot withdraw a package that is delivering
- As a post master
- I no need to register an account
- I only have 1 API, and when I call this API I need to submit the line name as a params, then I will process to fill packages and let the Train running on the selected line.
- The approach to pick a train
- if all packages need shipping when post master call API can ship on more than 1 trains => pick the cheapest train.
- if all packages need shipping when post master call API cannot ship on a train => pick the biggest train.
- When a train runs on a line, both the train and that line go unavailable status
can use postman with attached json file
- Get list of Lines
curl -H "Accept: application/json" "http://localhost:8080/api/lines"
- Get list of active Lines
In case a line has a issue, the status of that line changes to blocked
, and the system will not allow trains to run on that line anymore.
curl -H "Accept: application/json" "http://localhost:8080/api/lines/active"
- Create train operators
Each train operator will have 1 api_key and 1 name, api_key will be generated automatically, we just need to submit the name, but the name needs to be unique in the system.
curl -d '{"name": "kaka"}' -X POST -H "Content-Type: application/json" "http://localhost:8080/api/train_operators"
- Show all train operators in the system
It is not a good idea to have an API that returns information of all train operators along with api_key, this API is made for testing purpose.
curl -X GET -H "Content-Type: application/json" "http://localhost:8080/api/train_operators"
- Train operators submit a train
TO-7539 is the api_key
curl -d '{"max_weight": 100, "max_volume": 1, "cost": 100 ,"lines": ["A", "B"]}' -X POST \
-H "Content-Type: application/json" \
-H "Authorization: TO-7539" \
"http://localhost:8080/api/trains"
- Get all trains of a train operator
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: TO-7539" \
"http://localhost:8080/api/trains"
- Train operator withdraw a train
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: TO-7539" \
"http://localhost:8080/api/trains/1/withdraw"
- Train operator check status of their trains
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: TO-7539" \
"http://localhost:8080/api/trains/1/status"
- Customer create a basic account
Only require name, after creating will receive 1 api_key, use this api_key to send packages or check package status.
curl -d '{"name": "ronaldo"}' -X POST \
-H "Content-Type: application/json" \
"http://localhost:8080/api/customers"
- Customer submit a package
curl -d '{"weight": 100, "volume": 100000, "line": "C"}' -X POST \
-H "Content-Type: application/json" \
-H "Authorization: U-6492" \
"http://localhost:8080/api/packages"
- Customer check status of a package
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: U-6492" \
"http://localhost:8080/api/packages/13/status"
- Customer withdraw a package
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: U-6492" \
"http://localhost:8080/api/packages/13/withdraw"
- Post master process packages
curl -d '{"line": "A"}' -X POST \
-H "Content-Type: application/json" \
"http://localhost:8080/api/post_masters/process_packages"