This is a microservice for managing customer orders. It provides APIs for creating, retrieving, updating, and deleting orders. The service also includes a background job that synchronizes order data with Meilisearch on startup.
On startup, the service synchronizes existing order data with Meilisearch to ensure search accuracy. The sync job:
- Fetches all orders from the database.
- Indexes them into Meilisearch.
- Runs in the background to ensure search data is always up to date.
- Docker
- Docker Compose
- Wire (for dependency injection)
The wire dependency injection files can be found in the deps folder.
Install wire
go install github.com/google/wire/cmd/wire@latest
To create the dependency injection file launch:
./wiregen.sh
docker-compose up --build
This starts the following services:
- Redis
- MariaDB
- Meilisearch
- Order Service
docker-compose down
Variable | Description | Default Value |
---|---|---|
DATABASE_HOST |
Database host | mariadb |
DATABASE_PORT |
Database port | 3306 |
DATABASE_USER |
Database username | root |
DATABASE_PASSWORD |
Database password | password |
REDIS_HOST |
Redis host | redis |
REDIS_PORT |
Redis port | 6379 |
MEILISEARCH_HOST |
Meilisearch host | meilisearch |
MEILISEARCH_PORT |
Meilisearch port | 7700 |
MEILISEARCH_MASTER_KEY |
Meilisearch port | MASTER_API_KEY |
The database is initialized using an init.sql
file, which is automatically executed when MariaDB starts.
To manually connect to the database:
docker exec -it <mariadb-container-id> mysql -u root -p
Post Create Order
curl -X POST "http://localhost:8080/api/v1.0/order/" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1,
"items": [
{"product_id": 4, "quantity": 20},
{"product_id": 5, "quantity": 30}
]
}'
Get Order
curl -X GET "http://localhost:8080/api/v1.0/order/1"
Delete Order
curl -X DELETE "http://localhost:8080/api/v1.0/order/1"
Update Order
curl -X PUT "http://localhost:8080/api/v1.0/order/1" \
-H "Content-Type: application/json" \
-d '{
"items": [
{"product_id": 4, "quantity": 10},
{"product_id": 5, "quantity": 15}]
}'
List Order
curl -X GET "http://localhost:8080/api/v1.0/order?input=laptop&start_date=2025-03-29T12:30:00Z&end_date=2025-05-29T14:30:00Z&limit=10&offset=0" \
The swagger service is available on port 8081
http://localhost:8081/
To generate the swagger use this to convert the postman apis to swagger and run the swaggen.sh