git clone https://github.com/kaium123/order.gitgo mod tidy- Docker (for running containers)
- Docker Compose (for managing multi-container applications)
Run the following command to start the application locally, database, Redis, and Consul in docker container:
./run_local.shRun the following command to run the database, Redis, Consul, and the application within Docker containers:
./run_docker.sh- Endpoint:
/api/v1/login - Description: This endpoint allows users to authenticate with their credentials. Upon successful login, the API returns an access token and a refresh token that can be used to interact with the other API endpoints.
- Input:
{ "username": "01901901901@mailinator.com", "password": "321dsa" } - Response:
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzE4Njg4NTMsInVzZXJfaWQiOjF9.I0ePj4bvQsCW5rODb4uPBjSRt1bUCVmDIMcBYurhEKQ", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzI0NzAwNTMsInVzZXJfaWQiOjF9.LuQvDKekCPZGIxI9KlR0NxVJcUSnz6P6YQUppuj9EgQ", "token_type": "Bearer", "expire_in": 1731868853 }
- Endpoint:
/api/v1/logout - Description:
Allows the user to invalidate their session. The provided access and refresh tokens are revoked, ensuring the user is logged out securely. - Input:
- Access Token (in the header)
- Response:
{ "message": "Successfully logged out", "code": "200", "type": "success" }
- Endpoint:
/api/v1/orders - Description: Enables users to place new orders by providing necessary details.
- Input:
{ "store_id": 131172, "merchant_order_id": "123", "recipient_name": "kaium", "recipient_phone": "01875113838", "recipient_address": "banani, gulshan 2, dhaka, bangladesh", "recipient_city": 1, "recipient_zone": 1, "recipient_area": 1, "delivery_type": 2, ///1 - pickup, 2 - delivery, "item_type": 2, /// 1, document, 2 - parcel, 3 - other "special_instruction": "please provide as soon as possible", "item_quantity": 1, "item_weight": 0.5, "amount_to_collect": 12000, "item_description": "this is description" } - Response:
{ "message": "Order Created Successfully", "code": "200", "type": "success", "data": { "consignment_id": "DA241117FABNUY", "merchant_order_id": "123", "order_status": "Pending", "delivery_fee": 60 } }
- Endpoint:
/api/v1/orders/{CONSIGNMENT_ID}/cancel - Description: Users can cancel an existing order by providing the order ID. Orders that are already processed or delivered cannot be canceled.
- Input: CONSIGNMENT_ID (in the path)
- Response:
{ "message": "Order Cancelled Successfully", "code": "200", "type": "success" }
- Endpoint:
api/v1/orders/all - Description: Retrieve a list of all orders placed by the user. Supports filters.
- Input:
- Filters:
?limit=1&page=2&transfer_status=1&archive=0
- Filters:
- Response:
{ "message": "Orders successfully fetched.", "code": "200", "type": "success", "data": { "orders": [ { "order_consignment_id": "DA241117SIHWXX", "order_created_at": "2024-11-17T17:34:07.032741Z", "order_description": "this is description", "merchant_order_id": "123", "recipient_name": "kaium", "recipient_address": "banani, gulshan 2, dhaka, bangladesh", "recipient_phone": "01875113838", "order_amount": 12000, "total_fee": 180, "instruction": "please provide as soon as possible", "order_type_id": 1, "cod_fee": 120, "promo_discount": 0, "discount": 0, "delivery_fee": 60, "order_status": "Pending", "order_type": "Delivery", "item_type": "Parcel" } ], "total": 17, "current_page": 2, "per_page": 1, "total_in_page": 1, "last_page": 17 } }
To ensure that there is only one instance of the database and Redis connection throughout the application, I have utilized the Singleton Design Pattern. This pattern ensures that the database and Redis connections are created once, and that instance is reused whenever needed.
To improve the speed of data retrieval from the database, indexes are created on frequently queried columns. Indexing is particularly beneficial when working with large datasets and performing read-heavy operations. By adding indexes, the database can quickly locate rows without needing to scan the entire table.
To enhance performance, especially when dealing with read-heavy data, we have implemented Redis as a caching layer. Redis stores frequently accessed data in memory, allowing for fast retrieval without querying the database every time.
I follow Object-Oriented Programming (OOP) principles to make the application maintainable, scalable, and reusable: