From f7570f59575b2819bf2e50eb598bb739df44615f Mon Sep 17 00:00:00 2001 From: RyaWcksn Date: Sat, 8 Apr 2023 12:19:04 +0700 Subject: [PATCH 1/2] feat(DOCS): Add documentations and docker --- Ecommerce.postman_collection.json | 221 ++++++++++++++++++++++++++++++ README.md | 19 +++ apis/v1/services/service_impl.go | 1 - configs/config.yaml | 2 +- cov.out | 216 +++++++++++++++++++++++++++++ docker-compose.yml | 16 ++- migrate.sh | 3 + pkgs/database/mysql_connection.go | 2 + sql/005_master.sql | 48 +++++++ 9 files changed, 525 insertions(+), 3 deletions(-) create mode 100644 Ecommerce.postman_collection.json create mode 100644 cov.out create mode 100755 migrate.sh create mode 100644 sql/005_master.sql diff --git a/Ecommerce.postman_collection.json b/Ecommerce.postman_collection.json new file mode 100644 index 0000000..a7d06fa --- /dev/null +++ b/Ecommerce.postman_collection.json @@ -0,0 +1,221 @@ +{ + "info": { + "_postman_id": "88ed0e03-4670-49a1-8ddf-94998901a31b", + "name": "Ecommerce", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Login", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"user@mail.com\",\n \"password\": \"password123\",\n \"role\": \"buyer\"\n}" + }, + "url": { + "raw": "http://localhost:9000/api/v1/login", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "login" + ] + } + }, + "response": [] + }, + { + "name": "Create Product", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJlbWFpbCI6InVzZXJAbWFpbC5jb20iLCJleHAiOjE2ODA4NDA5MzgsImlkIjoxLCJyb2xlIjoiYnV5ZXIifQ.nCANSscjLFy3zUDkXoeuU-82nujolaoyi_BSkH5IN64", + "type": "string" + } + ] + }, + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJlbWFpbCI6InVzZXJAbWFpbC5jb20iLCJleHAiOiIxNjgwNzk2NTgyIiwiaWQiOiIxIiwicm9sZSI6InNlbGxlciJ9.64y5erHm71BfYLJXxXxUZy0J6vm3FufLO0rw54Pk7Wg", + "type": "default", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"HG Dynames Gundam\",\n \"description\": \"HG Dynames Gundam from Kidou Senshi Gundam 00\",\n \"price\": \"18000\"\n}" + }, + "url": { + "raw": "http://localhost:9000/api/v1/seller/create", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "seller", + "create" + ] + } + }, + "response": [] + }, + { + "name": "Get Seller products", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:9000/api/v1/seller/products", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "seller", + "products" + ] + } + }, + "response": [] + }, + { + "name": "Create Order", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"productId\": [1],\n \"sellerId\": 1\n}" + }, + "url": { + "raw": "http://localhost:9000/api/v1/order", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "order" + ] + } + }, + "response": [] + }, + { + "name": "Get all seller orders", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:9000/api/v1/seller/order", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "seller", + "order" + ] + } + }, + "response": [] + }, + { + "name": "Accept Order", + "request": { + "method": "PATCH", + "header": [], + "url": { + "raw": "http://localhost:9000/api/v1/seller/order/accept", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "seller", + "order", + "accept" + ] + } + }, + "response": [] + }, + { + "name": "Buyer list orders", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:9000/api/v1/orders", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "orders" + ] + } + }, + "response": [] + }, + { + "name": "Get Products", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJlbWFpbCI6InVzZXJAbWFpbC5jb20iLCJleHAiOjE2ODA5MjYyMzUsImlkIjoxLCJyb2xlIjoiYnV5ZXIifQ.0tXezwqgzCcU073i7e0xo5_02Lte65Z7kPMxtkjGvEM", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:9000/api/v1/products", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "9000", + "path": [ + "api", + "v1", + "products" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index e2a8fd4..c77c7e8 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Ecommerce for seller and buyer **Table of Contents** - [ecommerce](#ecommerce) + - [How to install](#how-to-install) - [Common Errors](#common-errors) - [Endpoints](#endpoints) - [Requests and Response](#requests-and-response) @@ -25,6 +26,24 @@ Ecommerce for seller and buyer +## How to install + +```bash +git clone https://github.com/RyaWcksn/ecommerce +cd ecommerce +docker-compose --build -d + +./migrate.sh +``` + +- Buyer account +> user@mail.com +> password123 + +- Seller account +> seller@mail.com +> password123 + ## Common Errors diff --git a/apis/v1/services/service_impl.go b/apis/v1/services/service_impl.go index 6d95de1..98be01e 100644 --- a/apis/v1/services/service_impl.go +++ b/apis/v1/services/service_impl.go @@ -94,7 +94,6 @@ func (s *ServiceImpl) GetProductsList(ctx context.Context, id int) (productList func (s *ServiceImpl) CreateOrder(ctx context.Context, payload *dto.CreateOrderRequest) (resp *entities.OrderStatus, err error) { idStr := ctx.Value("id").(string) id, _ := strconv.Atoi(idStr) - fmt.Println("ID", id) buyerData, err := s.buyerImpl.GetData(ctx, id) if err != nil { diff --git a/configs/config.yaml b/configs/config.yaml index 2dce9ee..248f990 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -6,7 +6,7 @@ app: server: httpaddress: "9000" database: - host: "127.0.0.1:3306" + host: "mysql:3306" username: "aya" password: "p4ssw0rd1" database: "ecommerce" diff --git a/cov.out b/cov.out new file mode 100644 index 0000000..c293dc3 --- /dev/null +++ b/cov.out @@ -0,0 +1,216 @@ +mode: set +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:15.88,20.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:20.16,23.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:24.2,24.54 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:24.54,27.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:29.2,29.53 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:29.53,32.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:34.2,35.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:35.16,38.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_order_handler.go:40.2,47.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:15.90,20.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:20.16,23.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:24.2,24.54 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:24.54,27.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:29.2,29.53 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:29.53,32.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:34.2,35.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:35.16,37.3 1 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/create_product_handler.go:39.2,46.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_buyer_order_handler.go:11.91,15.16 3 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_buyer_order_handler.go:15.16,18.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_buyer_order_handler.go:20.2,27.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_product_list_handler.go:12.92,18.16 5 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_product_list_handler.go:18.16,21.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_product_list_handler.go:22.2,29.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_products_handler.go:11.88,15.16 3 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_products_handler.go:15.16,18.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_products_handler.go:19.2,26.30 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_seller_orders_handler.go:11.92,15.16 3 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_seller_orders_handler.go:15.16,18.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/get_seller_orders_handler.go:20.2,27.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/handler.go:30.73,35.2 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:15.82,20.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:20.16,23.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:24.2,24.54 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:24.54,27.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:29.2,29.53 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:29.53,32.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:34.2,35.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:35.16,38.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/login_handler.go:39.2,46.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:15.88,20.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:20.16,23.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:24.2,24.54 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:24.54,27.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:29.2,29.53 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:29.53,32.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:34.2,35.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:35.16,38.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/update_order_handler.go:40.2,47.30 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/handlers/utils.go:11.66,14.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:38.36,40.2 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:42.67,45.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:47.69,50.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:52.72,55.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:57.69,60.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:62.73,65.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service.go:67.62,70.2 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:17.103,20.22 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:21.23,23.17 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:23.17,26.4 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:27.24,29.17 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:29.17,32.4 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:33.10,34.88 1 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:37.2,37.103 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:37.103,40.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:42.2,49.16 3 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:49.16,52.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:54.2,54.19 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:58.99,70.16 5 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:70.16,73.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:75.2,75.12 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:79.123,84.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:84.16,87.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:89.2,89.22 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:94.129,100.16 5 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:100.16,103.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:105.2,106.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:106.16,109.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:111.2,115.46 5 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:115.46,117.17 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:117.17,120.4 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:121.3,124.13 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:127.2,140.16 3 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:140.16,143.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:145.2,148.8 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:152.104,157.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:157.16,160.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:162.2,162.20 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:166.129,168.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:168.16,171.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:172.2,172.19 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:176.103,181.16 4 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:181.16,184.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:186.2,186.20 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:190.111,192.16 2 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:192.16,195.3 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_impl.go:197.2,197.22 1 1 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:28.61,32.2 3 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:35.59,37.2 1 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:40.121,46.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:49.88,52.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:55.100,60.2 4 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:63.90,66.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:69.90,75.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:78.85,81.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:84.96,90.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:93.79,96.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:99.108,105.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:108.87,111.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:114.91,120.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:123.86,126.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:129.94,135.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:138.82,141.2 2 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:144.121,150.2 5 0 +github.com/RyaWcksn/ecommerce/apis/v1/services/service_mock.go:153.94,156.2 2 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer.go:15.63,20.2 1 1 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:13.105,19.16 5 1 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:19.16,21.27 2 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:21.27,23.4 1 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:24.3,24.58 1 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:27.2,27.22 1 1 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:31.98,37.16 5 1 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:37.16,39.27 2 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:39.27,41.4 1 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:42.3,42.58 1 0 +github.com/RyaWcksn/ecommerce/domain/buyer/buyer_impl.go:45.2,45.22 1 1 +github.com/RyaWcksn/ecommerce/domain/order/order.go:15.62,20.2 1 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:13.90,18.16 4 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:18.16,21.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:23.2,24.16 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:24.16,27.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:29.2,32.16 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:32.16,36.3 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:38.2,39.16 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:39.16,43.3 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:44.2,44.13 1 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:44.13,48.3 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:50.2,51.16 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:51.16,54.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:56.2,56.12 1 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:60.107,70.16 7 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:70.16,73.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:74.2,76.18 2 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:76.18,91.17 3 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:91.17,94.4 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:95.3,97.17 3 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:97.17,100.4 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:102.3,102.39 1 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:105.2,105.24 1 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:109.97,117.16 6 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:117.16,120.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:122.2,123.16 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:123.16,126.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:128.2,131.16 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:131.16,135.3 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:137.2,138.16 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:138.16,141.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:143.2,157.16 4 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:157.16,160.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:162.2,164.16 3 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:164.16,167.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:169.2,169.24 1 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:173.106,183.16 7 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:183.16,186.3 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:187.2,189.18 2 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:189.18,204.17 3 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:204.17,207.4 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:208.3,210.17 3 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:210.17,213.4 2 0 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:215.3,215.39 1 1 +github.com/RyaWcksn/ecommerce/domain/order/order_impl.go:218.2,218.24 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product.go:15.64,20.2 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:13.102,18.16 4 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:18.16,21.3 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:23.2,24.16 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:24.16,27.3 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:29.2,32.16 3 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:32.16,36.3 3 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:38.2,39.16 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:39.16,43.3 3 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:44.2,44.13 1 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:44.13,48.3 3 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:50.2,51.16 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:51.16,54.3 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:56.2,56.12 1 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:61.116,68.16 5 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:68.16,71.3 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:72.2,74.18 2 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:74.18,77.125 2 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:77.125,80.4 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:82.3,82.47 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:85.2,85.27 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:89.116,95.16 5 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:95.16,97.27 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:97.27,99.4 1 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:100.3,100.58 1 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:103.2,103.22 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:107.114,114.16 5 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:114.16,117.3 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:118.2,120.18 2 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:120.18,123.125 2 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:123.125,126.4 2 0 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:128.3,128.47 1 1 +github.com/RyaWcksn/ecommerce/domain/product/product_impl.go:131.2,131.27 1 1 +github.com/RyaWcksn/ecommerce/domain/seller/seller.go:15.65,20.2 1 1 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:13.106,19.16 5 1 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:19.16,21.27 2 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:21.27,23.4 1 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:24.3,24.58 1 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:27.2,27.22 1 1 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:31.100,37.16 5 1 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:37.16,39.27 2 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:39.27,41.4 1 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:42.3,42.58 1 0 +github.com/RyaWcksn/ecommerce/domain/seller/seller_impl.go:45.2,45.22 1 1 diff --git a/docker-compose.yml b/docker-compose.yml index 81be014..5519322 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,20 +4,34 @@ services: mysql: image: mysql:latest restart: always + command: --default-authentication-plugin=mysql_native_password + container_name: mysql environment: MYSQL_ROOT_PASSWORD: aya MYSQL_DATABASE: ecommerce MYSQL_USER: aya MYSQL_PASSWORD: p4ssw0rd1 + MYSQL_ROOT_HOST: '%' ports: - "3306:3306" volumes: - ~/mysql_data:/var/lib/mysql + ecommerce: + build: + context: . + dockerfile: ./dockerfile + container_name: ecommerce + ports: + - "9000:9000" + depends_on: + - "mysql" + redis: image: redis:latest restart: always + container_name: redis ports: - "6379:6379" volumes: - - ~/redis_data:/data \ No newline at end of file + - ~/redis_data:/data diff --git a/migrate.sh b/migrate.sh new file mode 100755 index 0000000..c959779 --- /dev/null +++ b/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +mysql -u aya -h 127.0.0.1 -P 3306 -pp4ssw0rd1 ecommerce < sql/005_master.sql diff --git a/pkgs/database/mysql_connection.go b/pkgs/database/mysql_connection.go index 385635d..c614f56 100644 --- a/pkgs/database/mysql_connection.go +++ b/pkgs/database/mysql_connection.go @@ -25,10 +25,12 @@ func (db *Connection) DBConnect() *sql.DB { "mysql", db.MYSQL.Database.Username+":"+db.MYSQL.Database.Password+"@tcp("+db.MYSQL.Database.Host+")/"+db.MYSQL.Database.Database, ) if errConn != nil { + db.L.Errorf("[ERR] Error while connecting... := %v", errConn) return nil } errPing := dbConn.Ping() if errPing != nil { + db.L.Errorf("[ERR] Error while pingging... := %v", errPing) return nil } dbConn.SetMaxIdleConns(db.MYSQL.Database.MaxIdleConn) diff --git a/sql/005_master.sql b/sql/005_master.sql new file mode 100644 index 0000000..4ddef1b --- /dev/null +++ b/sql/005_master.sql @@ -0,0 +1,48 @@ +CREATE TABLE IF NOT EXISTS buyer ( + id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, + email VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL, + alamat_pengiriman VARCHAR(255) NOT NULL +); + + +INSERT INTO buyer (email, name, password, alamat_pengiriman) +VALUES ('user@mail.com', 'John Doe', '$2a$10$xCniCdjZENytpQ7/NTNQduSJaZ6pl3bFMbd7bfF4OLwwbCyhGH8rC', '123 Main St'); + + +CREATE TABLE IF NOT EXISTS seller ( + id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, + email VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL, + alamat_pickup VARCHAR(255) NOT NULL +); + + +INSERT INTO seller (email, name, password, alamat_pickup) +VALUES ('seller@mail.com', 'John Doe', '$2a$10$xCniCdjZENytpQ7/NTNQduSJaZ6pl3bFMbd7bfF4OLwwbCyhGH8rC', '123 Main St'); + +CREATE TABLE IF NOT EXISTS product ( + id INT AUTO_INCREMENT PRIMARY KEY, + product_name VARCHAR(255) NOT NULL, + description VARCHAR(255) NOT NULL, + price DECIMAL(10, 2) NOT NULL, + seller INT NOT NULL, + FOREIGN KEY (seller) REFERENCES seller(id) +); + +CREATE TABLE IF NOT EXISTS orders ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + buyer INT NOT NULL, + seller INT NOT NULL, + delivery_source_address VARCHAR(255) NOT NULL, + delivery_destination_address VARCHAR(255) NOT NULL, + items VARCHAR(255) NOT NULL, + quantity INT NOT NULL, + price DECIMAL(10, 2) NOT NULL, + total_price DECIMAL(10, 2) NOT NULL, + status INT NOT NULL DEFAULT 0, + FOREIGN KEY (buyer) REFERENCES buyer(id), + FOREIGN KEY (seller) REFERENCES seller(id) +); From dd0bdbdbde47bc4040f0f621ab601fe98e3dbb49 Mon Sep 17 00:00:00 2001 From: RyaWcksn Date: Sat, 8 Apr 2023 12:29:58 +0700 Subject: [PATCH 2/2] feat(OPS): Resolve unable to connect docker sql container --- docker-compose.yml | 2 +- pkgs/database/mysql_connection.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5519322..b6b83dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: mysql: image: mysql:latest - restart: always + restart: unless-stopped command: --default-authentication-plugin=mysql_native_password container_name: mysql environment: diff --git a/pkgs/database/mysql_connection.go b/pkgs/database/mysql_connection.go index c614f56..26631cc 100644 --- a/pkgs/database/mysql_connection.go +++ b/pkgs/database/mysql_connection.go @@ -2,6 +2,7 @@ package database import ( "database/sql" + "time" "github.com/RyaWcksn/ecommerce/configs" "github.com/RyaWcksn/ecommerce/pkgs/logger" @@ -28,10 +29,9 @@ func (db *Connection) DBConnect() *sql.DB { db.L.Errorf("[ERR] Error while connecting... := %v", errConn) return nil } - errPing := dbConn.Ping() - if errPing != nil { - db.L.Errorf("[ERR] Error while pingging... := %v", errPing) - return nil + for dbConn.Ping() != nil { + db.L.Info("Attempting connect to DB...") + time.Sleep(5 * time.Second) } dbConn.SetMaxIdleConns(db.MYSQL.Database.MaxIdleConn) dbConn.SetMaxOpenConns(db.MYSQL.Database.MaxOpenConn)