This document provides comprehensive instructions on setting up and configuring the Superindo API project. It includes steps for both Docker container deployment and local machine setup using a .env
file.
- Language: Golang
- Database: Mysql + Gorm (Seeder + Migration)
- Cache: Redis
- Router: Echo
- Unit Test
- Logger
- Docker
Before you start, make sure you have the following:
- Docker installed on your machine.
To run the application using Docker, follow these steps:
-
Run Docker Compose: Execute the following command to launch the application along with its dependencies:
docker-compose up
Note: Wait until the MySQL container, Redis, and the API application are running correctly.
-
Base URL for API app: Once the containers are up and running, access the API using the following base URL:
http://localhost:5580
To set up the application on your local machine, follow these steps:
-
Copy the
.env.example
file:If you don't have an
.env
file, start by copying the provided.env.example
file.cp .env.example .env
-
Open the .env file:
Use your preferred text editor to open the .env file.
nano .env
-
Update the Database Configuration:
Locate the database configuration section in the .env file. Update it to match your provided database information:
DB_HOST=your_database_host DB_PORT=your_database_port DB_DATABASE=your_database_name DB_USERNAME=your_database_username DB_PASSWORD=your_database_password DB_DEBUG=false
Replace the placeholder values (
your_database_name
,your_database_user
,your_database_password
) with your actual database information. SetDB_DEBUG
totrue
if you want to enable query logging to the console.REDIS_HOST=your_redis_host REDIS_PORT=your_redis_port REDIS_PASSWORD=your_redis_password REDIS_USERNAME=your_redis_username
Replace the placeholder values (
your_redis_host
,your_redis_port
,your_redis_password
,your_redis_username
) with your actual redis information. -
Logger Configuration:
Add the following lines for logger configuration:
LOGGER_LOGS_WRITE=true LOGGER_FOLDER_PATH=./logs
Adjust the LOGGER_FOLDER_PATH based on your preferred folder structure.
-
Ensure that the application is configured with the following environment variable:
APP_PORT=5580
-
Save and Close the File:
Save the changes and close the .env file.
-
Verify the Configuration:
Make sure your application can connect to the database using the updated configuration. You can do this by running a database-related task or checking your application logs.
-
Run Unit Testing:
Execute the following command to run unit tests and generate a coverage report:
make test
- Import Postman Collection: Use Postman to import the provided collection file Superindo Postman to your postman for testing superindo API.
This documentation outlines the usage of the Simple API, providing details on various endpoints and their functionalities.
- Method: GET
- Endpoint:
http://localhost:5580/category
- Response:
{ "code": 200, "message": "Success", "data": [ { "id": 1, "name": "Sayuran" }, { "id": 2, "name": "Protein" }, { "id": 3, "name": "Buah dan Snack" } ] }
- Method: POST
- Endpoint:
http://localhost:5580/product
- Request Body:
{ "name": "indomie rasa ayam bawang", "description": "mie dengan rasa yang nendang ayam bawang goreng", "weight": 300, "price": 2500, "image": "http://google.com/mie-indomie-ayam-bawang.jpg", "categoryId": 3 }
- Response:
{ "code": 200, "message": "Success", "data": { "id": "7aec2d81-0313-42bf-8e0e-b40730e31ddf" } }
- Method: GET
- Endpoint:
http://localhost:5580/product?page=1&limit=10
- Query Parameters:
search
(string): indomiecategoryId
(int): 3minPrice
(int): 1000maxPrice
(int): 3000createdAt
(date format): 2024-03-18productName
(string): wortelpage
(int): 1limit
(int): 10
- Response:
{ "code": 200, "message": "Success", "data": [ { "id": "1b61b02c-78bb-4b41-bfcf-c1c9c3b67158", "name": "Indomie Kuah Rasa Soto", "description": "Mie instan dengan kuah soto yang khas dan gurih.", "weight": 350, "price": 2800, "image": "http://example.com/mie-indomie-kuah-soto.jpg", "categoryId": 3, "createdAt": "2024-03-20T10:45:39.826Z" }, { "id": "229af19a-1614-4ed4-9b4e-55f6e6d45e51", "name": "Roti Whole Wheat", "description": "Roti gandum utuh yang kaya serat dan nutrisi.", "weight": 350, "price": 2500, "image": "http://example.com/roti-whole-wheat.jpg", "categoryId": 3, "createdAt": "2024-03-18T10:44:39.826Z" }, ], "pagination": { "page": 1, "limit": 10, "totalData": 2, "totalPage": 1 } }
- Method: GET
- Endpoint:
http://localhost:5580/product/22c8e385-6d60-4ddb-87b2-3fb543d43177
- Response:
{ "code": 200, "message": "Success", "data": { "name": "indomie rasa ayam bawang cincang", "description": "mie dengan rasa yang nendang ayam bawang goreng", "weight": 300, "price": 2500, "categoryId": 2, "categoryName": "Protein", "image": "http://google.com/mie-indomie-ayam-bawang.jpg", "createdAt": "2024-03-20T11:43:39.826Z" } }
- Method: PUT
- Endpoint:
http://localhost:5580/product/b34e8eac-ac43-4163-b9ad-49f15644b4fa
- Request Body:
{ "name": "indomie rasa ayam bawang cincang", "description": "mie dengan rasa yang nendang ayam bawang goreng", "weight": 300, "price": 2500, "image": "http://google.com/mie-indomie-ayam-bawang.jpg", "categoryId": 3 }
- Response:
{ "code": 200, "message": "Success", "data": null }
- Method: DELETE
- Endpoint:
http://localhost:5580/product/22c8e385-6d60-4ddb-87b2-3fb543d43177
- Response:
{ "code": 200, "message": "Success", "data": null }