Skip to content

Commit

Permalink
Merge pull request #19 from aasumitro/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
aasumitro committed Dec 7, 2022
2 parents 5deacc9 + 99bdb1f commit cf60f58
Show file tree
Hide file tree
Showing 29 changed files with 1,866 additions and 55 deletions.
1 change: 0 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Run Linter
on:
push:
branches:
- main
- dev
pull_request:
branches:
Expand Down
4 changes: 2 additions & 2 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func initEngine() {
gin.SetMode(gin.ReleaseMode)
}

accessLogFile, _ := os.Create("./tmp/access.log")
accessLogFile, _ := os.Create("./temps/access.log")
gin.DefaultWriter = io.MultiWriter(accessLogFile, os.Stdout)

errorLogFile, _ := os.Create("./tmp/errors.log")
errorLogFile, _ := os.Create("./temps/errors.log")
gin.DefaultErrorWriter = io.MultiWriter(errorLogFile, os.Stdout)

appEngine = gin.Default()
Expand Down
4 changes: 3 additions & 1 deletion db/migrations/20221206065324_add_common_catalog_data.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ VALUES (1, 'meat'), (1, 'seafood'), (2, 'coffee'), (2, 'juice');
INSERT INTO units (magnitude, name, symbol)
VALUES ('mass', 'gram', 'g'),
('mass', 'milligram', 'mg'),
('mass', 'kilogram', 'kg');
('mass', 'kilogram', 'kg'),
('mass', 'milliliter', 'ml'),
('mass', 'liter', 'l');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS products;
17 changes: 17 additions & 0 deletions db/migrations/20221207075900_create_table_products.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS products (
id BIGSERIAL PRIMARY KEY NOT NULL,
category_id BIGINT NOT NULL,
subcategory_id BIGINT NOT NULL,
sku VARCHAR(255) UNIQUE NOT NULL,
image VARCHAR(255),
gallery TEXT,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
price FLOAT NOT NULL
);

ALTER TABLE products ADD CONSTRAINT fk_products_categories
FOREIGN KEY (category_id) REFERENCES categories(id);

ALTER TABLE products ADD CONSTRAINT fk_products_subcategories
FOREIGN KEY (subcategory_id) REFERENCES subcategories(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS addons;
10 changes: 10 additions & 0 deletions db/migrations/20221207075911_create_table_product_addons.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS addons(
id BIGSERIAL PRIMARY KEY NOT NULL,
-- product_id BIGINT NOT NULL,
name VARCHAR(255),
description VARCHAR(255),
price FLOAT
);

-- ALTER TABLE product_addons ADD CONSTRAINT fk_products_product_addons
-- FOREIGN KEY (product_id) REFERENCES products(id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS product_variants;
DROP TYPE IF EXISTS variant_types;
18 changes: 18 additions & 0 deletions db/migrations/20221207075916_create_table_product_variants.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TYPE variant_types AS ENUM ('none', 'size');

CREATE TABLE IF NOT EXISTS product_variants(
id BIGSERIAL PRIMARY KEY NOT NULL,
product_id BIGINT NOT NULL,
unit_id BIGINT NOT NULL,
unit_size FLOAT,
type VARIANT_TYPES DEFAULT 'none',
name VARCHAR(255),
description VARCHAR(255),
price FLOAT
);

ALTER TABLE product_variants ADD CONSTRAINT fk_products_product_variants
FOREIGN KEY (product_id) REFERENCES products(id);

ALTER TABLE product_variants ADD CONSTRAINT fk_units_product_variants
FOREIGN KEY (unit_id) REFERENCES units(id);
17 changes: 17 additions & 0 deletions db/migrations/20221207082217_add_product_data.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INSERT INTO addons (name, description, price)
VALUES ('oat milk', 'replace', 1),
('raw milk', 'replace', 1),
('cheese', 'extra cheese', 1),
('chocolate', 'extra chocolate', 1);

INSERT INTO products (category_id, subcategory_id, sku, name, description, price)
VALUES (2, 4, 'JMGO100', 'mango juice', 'this sweet, tangy, and fruity tropical juice can be made using a blender, handheld blender, or a food processor in under 5 minutes.', 25),
(1, 2, 'WA5S100', 'wagyu a5 steak', 'The highest yield grade and meat quality grade for Wagyu beef is A5, where A represents the yield grade, and 5 represents the meat quality grade. A5 Wagyu beef denotes meat with ideal firmness and texture, coloring, yield, and beef marbling score.', 100);

INSERT INTO product_variants (product_id, type, name, description, unit_id, unit_size, price)
VALUES (1, 'size', 's', 'small', 4, 250, 0),
(1, 'size', 'm', 'medium', 4, 480, 2),
(1, 'size', 'l', 'large', 4, 650, 3),
(1, 'size', 'xl', 'extra large', 5, 1.5, 1),
(2, 'size', 'half', 'half portion', 1, 250, 0),
(2, 'size', 'normal', 'normal portion', 1, 500, 100);
280 changes: 280 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,264 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/v1/addons": {
"get": {
"description": "Get Addons List.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Addons"
],
"summary": "Addons List",
"responses": {
"200": {
"description": "OK RESPOND",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.SuccessRespond"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.Addon"
}
}
}
}
]
}
},
"401": {
"description": "UNAUTHORIZED RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"500": {
"description": "INTERNAL SERVER ERROR RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
}
}
},
"post": {
"description": "Create new addon.",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"Addons"
],
"summary": "Store addon Data",
"parameters": [
{
"type": "string",
"description": "name",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "description",
"name": "description",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "price",
"name": "price",
"in": "formData",
"required": true
}
],
"responses": {
"201": {
"description": "CREATED RESPOND",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.SuccessRespond"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.Addon"
}
}
}
]
}
},
"401": {
"description": "UNAUTHORIZED RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"422": {
"description": "UNPROCESSABLE ENTITY RESPOND",
"schema": {
"$ref": "#/definitions/utils.ValidationErrorRespond"
}
},
"500": {
"description": "INTERNAL SERVER ERROR RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
}
}
}
},
"/v1/addons/{id}": {
"put": {
"description": "Update addon Data by ID.",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"Addons"
],
"summary": "Update addon Data",
"parameters": [
{
"type": "integer",
"description": "addon id",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "description",
"name": "description",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "price",
"name": "price",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "CREATED RESPOND",
"schema": {
"allOf": [
{
"$ref": "#/definitions/utils.SuccessRespond"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.Addon"
}
}
}
]
}
},
"400": {
"description": "BAD REQUEST RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"401": {
"description": "UNAUTHORIZED RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"422": {
"description": "UNPROCESSABLE ENTITY RESPOND",
"schema": {
"$ref": "#/definitions/utils.ValidationErrorRespond"
}
},
"500": {
"description": "INTERNAL SERVER ERROR RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
}
}
},
"delete": {
"description": "Delete addon Data by ID.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Addons"
],
"summary": "Delete addon Data",
"parameters": [
{
"type": "integer",
"description": "category id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "NO CONTENT RESPOND"
},
"400": {
"description": "BAD REQUEST RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"401": {
"description": "UNAUTHORIZED RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
},
"500": {
"description": "INTERNAL SERVER ERROR RESPOND",
"schema": {
"$ref": "#/definitions/utils.ErrorRespond"
}
}
}
}
},
"/v1/categories": {
"get": {
"description": "Get Categories List.",
Expand Down Expand Up @@ -2509,6 +2767,28 @@ const docTemplate = `{
}
},
"definitions": {
"domain.Addon": {
"type": "object",
"required": [
"description",
"name",
"price"
],
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"price": {
"type": "number"
}
}
},
"domain.Category": {
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit cf60f58

Please sign in to comment.