Design and implement a system that allows users to track and trace supply chain items.
The system will have two main components:
- REST API
- Web Application
The REST API must offer an interface with this set of functions at a minimum:
- Create a new supply chain item
- Update supply chain item reference data (colour, price, etc.)
- Add new events associated with an item (for instance, where the item is, who has the custody, etc.)
- Query all events of an item. Particularly, a shortcut to get the last event will be quite helpful to know the current location / custodian of the item.
- You can implement using your favourite programming language / framework, database and cloud environment for the backend.
The following non-functional requirements also need to be met.
- An OpenAPI / Swagger specification for the API built
- A JSON Schema that can also be used at runtime for payload validation purposes
- A Dockerfile for deployment of the API.
-
Install NodeJS on your host machine
-
Install RabbitMQ on your host machine / Docker image
-
Clone this repository and make it the active directory
git clone https://github.com/SrMoffat/iota-logistics-backend.git
cd iota-logistics-backend
- Install dependencies
yarn OR npm install
- Export environment variables (After adding correct values to
.env
as per.env.example
)
cat .env.example >> .env
- Export environment variables
set -o allexport; source .env; set +o allexport
- Start the app
yarn develop:watch (for hot reload)
NB: This will start two platforms:
1. Admin Portal Webapp on `http://localhost:8000`
1. API Server on `http://localhost:1337`
It will also automaticslly initialize an SQLite database locally
- Open the browser window on
http://localhost:8000
for admin panel webapp - Add a super admin user (needed to manage the admin panel and endpoint permissions)
- Visit the API url using Postman, Insomnia or any HTTP client of your choice at
http://localhost:1337/api
- Sign a user up on this endpoint
POST `http://localhost:1337/api/auth/local/register`
{
"username": "username",
"email": "email",
"password": "password"
}
- Login as super admin on the admin panel and make endpoint accessible by:
Settings > Users & Permissions > Roles > Authenticated
Allow the endpoint under `Stage` `seedStagesAndStatuses` i.e. POST /api/stages/seed
- Seed the database with config tables by making this request
POST http://localhost:1337/api/stages/seed (Use token from previous step 9 as Bearer <token> in the headers)
No body is required
Success will respond with
{
"success": true,
"message": "Seed was successful for Stage, Status, Category and Currency models"
}
- Interact with API endpoints as outlined in this documentation:
PS
: Everytime you get403 Forbidden
error, repeat Step 11 to allow the endpoint to be accessible (this is done only once when setting up)
1. Sign Up: POST http://localhost:1337/api/auth/local/register
2. Login: POST http://localhost:1337/api/auth/local
3. Seed DB: POST http://localhost:1337/api/stages/seed
4. Add Supply Chain Item: POST http://localhost:1337/api/supply-items (Also publishes a message to RabbitMQ under new-product-created queue)
5. Update Supply Chain Item: PUT http://localhost:1337/api/supply-items
6. Add Events to Supply Chain Item: PUT http://localhost:1337/api/supply-items/:id/events