- This small project is developed using Gin (Golang Framework) and MongoDB Atlas as NoSQL database.
-
The primary reason is I am working in node.js and Golang for a while , and I have experience of migrating spring boot , node.js backend project to Golang framework and acheive better experience in terms of speed , build size and build process.
-
Golang is compiled into machine code, which means that it runs much faster than interpreted languages like Node.js
-
The Goal of the project is to provide status of the card based on the combined data present in the CSV file.
-
The connection is established with MongoDB atlas database.
-
Application will start with loading all the data from csv into the database (MongoDB atlas).
-
It will parse the csv files and creating the collection of card in the mongoDB.
-
Then endpoint exposed to query the status of the card based on user_id or card_id.
-
One additional thing could be done is to schedule the Cron Job to get the data from the data folder and load into database so that it will fetch the latest status of the card.
-
The End point
get_card_status
will fetch following four types of status with timestamps- DELIVERED : card delivered with timestamp
- PICKED_UP : card picked up with timestamp
- EXCEPTION : card exception with timestamp and comment
- RETURNED : card returned due to exception
-
Following the sample response of the endpoint hit with card_id = "ZYW8890"
{
"card status": [
{
"card_id": "ZYW8890",
"user_id": "0534534534",
"status": "EXCEPTION",
"comment": "User not available",
"timestamp": "2023-12-22T04:18:41.492Z"
},
{
"card_id": "ZYW8890",
"user_id": "534534534",
"status": "PICKED_UP",
"comment": "",
"timestamp": "2023-12-22T04:18:42.412Z"
},
{
"card_id": "ZYW8890",
"user_id": "971534534534",
"status": "RETURNED",
"comment": "",
"timestamp": "2023-12-22T04:18:43.346Z"
}
]
}
Create an internal API that would return the status of a user’s card. We need a service that would combine the data from our partner companies and return the current status of a card when queried for by a team mate.
Click to expand
Internally, let’s say we identify a user with their phone number, and for this particular task, let us ignore the country code, and set it to be a 9 digit number. A user’s card has a unique identifier as well, and for this task, we can assume that all entities involved uses the same ID to refer to the card.
Here’s a top level flow of what happens to a card
- Card is generated by us
- Card is picked up by courier partner
- Card is delivered
- If the Card could not be delivered, re-delivery is attempted maximum of two times
- If all attempts of delivery fail, it is returned to us
- Clone the project
git clone https://github.com/gauravshinde1816/card_tracker.git
-
Start backend
cd card_tracker/
- Install Dependancies
go mod tidy
- Start server
go run main.go
-
Use to
http://localhost:8080/get_card_status
to get the status of card using user_id and card_id.
- Run
docker-compose up -d
- Use to
http://localhost:8080/get_card_status
to get the status of card using user_id and card_id.