From ed762f41b24b30436380cc57840fb35d12bf22d6 Mon Sep 17 00:00:00 2001 From: Dmitry Shurco Date: Mon, 20 Nov 2023 15:51:57 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20show=20products=20without?= =?UTF-8?q?=20filled=20digital=20goods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/models/products.go | 11 +-- internal/queries/products.go | 11 +++ web/admin/src/components/product/Add.vue | 1 - web/admin/src/components/product/Digital.vue | 80 +++++++++++++------- web/admin/src/components/product/Update.vue | 1 - web/admin/src/pages/Products.vue | 14 ++-- 6 files changed, 76 insertions(+), 42 deletions(-) diff --git a/internal/models/products.go b/internal/models/products.go index d5c2043..303f90a 100644 --- a/internal/models/products.go +++ b/internal/models/products.go @@ -59,9 +59,10 @@ func (v Metadata) Validate() error { // Digital is ... type Digital struct { - Type string `json:"type"` - Files []File `json:"files,omitempty"` - Data []Data `json:"data,omitempty"` + Type string `json:"type"` + Filled bool `json:"filled,omitempty"` + Files []File `json:"files,omitempty"` + Data []Data `json:"data,omitempty"` } // Validate is ... @@ -86,7 +87,7 @@ func (v File) Validate() error { return validation.ValidateStruct(&v, validation.Field(&v.ID, validation.Length(15, 15)), validation.Field(&v.Name, is.UUIDv4), - //validation.Field(&v.Ext, validation.In("jpeg", "png")), + // validation.Field(&v.Ext, validation.In("jpeg", "png")), ) } @@ -102,6 +103,6 @@ func (v Data) Validate() error { return validation.ValidateStruct(&v, validation.Field(&v.ID, validation.Length(15, 15)), validation.Field(&v.Content, validation.Length(1, 254)), - //validation.Field(&v.Ext, validation.In("jpeg", "png")), + // validation.Field(&v.Ext, validation.In("jpeg", "png")), ) } diff --git a/internal/queries/products.go b/internal/queries/products.go index 23f348e..fb6fd6b 100644 --- a/internal/queries/products.go +++ b/internal/queries/products.go @@ -37,6 +37,11 @@ func (q *ProductQueries) ListProducts(private bool, idList ...models.CartProduct product.amount, product.active, product.digital, + CASE + WHEN (SELECT COUNT(id) FROM digital_data WHERE product_id = product.id AND cart_id IS NULL) > 0 THEN TRUE + WHEN (SELECT COUNT(id) FROM digital_file WHERE product_id = product.id) > 0 THEN TRUE + ELSE FALSE + END digital_filled, (SELECT json_group_array(json_object('id', product_image.id, 'name', product_image.name, 'ext', product_image.ext)) as images FROM product_image WHERE product_id = product.id GROUP BY id LIMIT 1) as image, strftime('%s', created) FROM product @@ -72,6 +77,7 @@ func (q *ProductQueries) ListProducts(private bool, idList ...models.CartProduct for rows.Next() { var image, digitalType sql.NullString + var digitalFilled sql.NullBool product := models.Product{} err := rows.Scan( &product.ID, @@ -80,6 +86,7 @@ func (q *ProductQueries) ListProducts(private bool, idList ...models.CartProduct &product.Amount, &product.Active, &digitalType, + &digitalFilled, &image, &product.Created, ) @@ -95,6 +102,10 @@ func (q *ProductQueries) ListProducts(private bool, idList ...models.CartProduct product.Digital.Type = digitalType.String } + if private && digitalType.Valid { + product.Digital.Filled = digitalFilled.Bool + } + products.Products = append(products.Products, product) } diff --git a/web/admin/src/components/product/Add.vue b/web/admin/src/components/product/Add.vue index 77098ff..2acd714 100644 --- a/web/admin/src/components/product/Add.vue +++ b/web/admin/src/components/product/Add.vue @@ -121,7 +121,6 @@ const product = ref({ }) const emits = defineEmits(["update:modelValue"]); - const products = computed({ get: () => { return props.products; diff --git a/web/admin/src/components/product/Digital.vue b/web/admin/src/components/product/Digital.vue index ce00e4c..acdc1ba 100644 --- a/web/admin/src/components/product/Digital.vue +++ b/web/admin/src/components/product/Digital.vue @@ -4,7 +4,8 @@

Digital {{ digital.type }}

-

This is the product that the user purchases. Upload the files that will be sent to the buyer after payment to the email address provided during checkout.

+

This is the product that the user purchases. Upload the files that will be sent to the buyer after payment to the email + address provided during checkout.

Enter the digital product that you intend to sell. It can be a unique item, such as a license key.

@@ -57,7 +58,7 @@ diff --git a/web/admin/src/components/product/Update.vue b/web/admin/src/components/product/Update.vue index 1d302c6..08dfabf 100644 --- a/web/admin/src/components/product/Update.vue +++ b/web/admin/src/components/product/Update.vue @@ -128,7 +128,6 @@ const amount = ref() const product = ref({}) const emits = defineEmits(["update:modelValue"]); - const products = computed({ get: () => { return props.products; diff --git a/web/admin/src/pages/Products.vue b/web/admin/src/pages/Products.vue index bce3bdd..c40c652 100644 --- a/web/admin/src/pages/Products.vue +++ b/web/admin/src/pages/Products.vue @@ -40,7 +40,7 @@ {{ costFormat(item.amount) }} {{ products.currency }} - +
@@ -62,11 +62,11 @@
Add first product
- - - - - + + + + + @@ -129,7 +129,7 @@ const updateProductActive = async (index) => { const openDrawer = (index, action) => { isDrawer.value.open = true; isDrawer.value.action = action; - if (index!==null) { + if (index !== null) { isDrawer.value.product = { index: index, id: products.value.products[index].id,