From f2aedd7a98f52fd9b8dfa75f8759e8c9d12a54af Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Mon, 27 May 2024 02:42:22 +0700 Subject: [PATCH] update db --- .../modules/storage/storage_file/storage.go | 57 +- resources/catalog.json | 14 +- resources/products.json | 1077 ++++++++++++++++- 3 files changed, 1109 insertions(+), 39 deletions(-) diff --git a/internal/modules/storage/storage_file/storage.go b/internal/modules/storage/storage_file/storage.go index d6e8d50..874040b 100644 --- a/internal/modules/storage/storage_file/storage.go +++ b/internal/modules/storage/storage_file/storage.go @@ -9,6 +9,21 @@ import ( "os" ) +type Product struct { + Id int64 `json:"id"` + Article string `json:"article"` + Name string `json:"name"` + Uri string `json:"uri"` + Images []string `json:"images"` + Description string `json:"description"` + Group int64 `json:"group"` + Unit string `json:"unit"` + Inventory float64 `json:"inventory"` + Variants []*crm.Variant `json:"variants"` + Characteristics []*crm.Characteristic `json:"characteristics"` + Category int64 `json:"category"` +} + var ( ErrProductNotFound = errors.New("product not found") ) @@ -54,16 +69,48 @@ func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, err if err != nil { return nil, err } - var products []*crm.Product + var products []*Product if err := json.Unmarshal(data, &products); err != nil { return nil, err } - for _, product := range products { - if product.Id == id { - return product, nil + var product *Product + for _, p := range products { + if p.Id == id { + product = p + break } } - return nil, ErrProductNotFound + if product == nil { + return nil, ErrProductNotFound + } + res := &crm.Product{ + Id: product.Id, + Article: product.Article, + Name: product.Name, + Uri: product.Uri, + Images: product.Images, + Description: product.Description, + GroupedProducts: nil, + Unit: product.Unit, + Inventory: product.Inventory, + Variants: product.Variants, + Characteristics: product.Characteristics, + Category: product.Category, + } + for _, p := range products { + if p.Group == product.Group { + image := "" + if len(product.Images) > 0 { + image = p.Images[0] + } + res.GroupedProducts = append(res.GroupedProducts, &crm.GroupedProduct{ + Name: p.Name, + Uri: p.Uri, + Image: image, + }) + } + } + return res, nil } func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) { diff --git a/resources/catalog.json b/resources/catalog.json index 6b9331e..2298092 100644 --- a/resources/catalog.json +++ b/resources/catalog.json @@ -12,9 +12,21 @@ }, { "id": 2, - "name": "Пахлава", + "name": "Печенье бисквитное", "uri": "/categories/2", "children": [] + }, + { + "id": 3, + "name": "Печенье песочное", + "uri": "/categories/3", + "children": [] + }, + { + "id": 4, + "name": "Восточные сладости", + "uri": "/categories/4", + "children": [] } ] } diff --git a/resources/products.json b/resources/products.json index ff57a03..c7cd111 100644 --- a/resources/products.json +++ b/resources/products.json @@ -1,27 +1,12 @@ [ { "id": 1, - "article": "1", + "article": "_", "name": "\"Глаголик\" ванильно-сливочный", "uri": "/products/1", - "images": [ - "/products/1/image-1-600x600.jpg", - "/products/1/image-2-600x600.jpg", - "/products/1/image-3-600x600.jpg" - ], + "images": [], "description": "", - "grouped_products": [ - { - "name": "\"Глаголик\" лимонный", - "uri": "/products/2", - "image": "/products/2/image-100x100.jpg" - }, - { - "name": "\"Глаголик\" мятный", - "uri": "/products/3", - "image": "/products/3/image-100x100.jpg" - } - ], + "group": 1, "unit": "kg", "inventory": 100, "variants": [ @@ -61,28 +46,963 @@ ] } ], - "characteristics": [ + "characteristics": [], + "category": 1 + }, + { + "id": 2, + "article": "_", + "name": "\"Глаголик\" лимонный", + "uri": "/products/2", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ { - "name": "Вкус", - "value": "Ванильно-сливочный" + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] } ], + "characteristics": [], + "category": 1 + }, + { + "id": 3, + "article": "_", + "name": "\"Глаголик\" мятный", + "uri": "/products/3", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], "category": 1 }, { "id": 4, - "article": "4", - "name": "Пахлава ореховая экран 1,5 кг", + "article": "_", + "name": "\"Глаголик\" клубничный", "uri": "/products/4", - "images": [ - "/products/4/image-1-600x600.jpg", - "/products/4/image-2-600x600.jpg", - "/products/4/image-3-600x600.jpg" - ], + "images": [], "description": "", - "grouped_products": [], + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 1 + }, + { + "id": 5, + "article": "_", + "name": "\"Глаголик\" шоколадный", + "uri": "/products/5", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 17000, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 1 + }, + { + "id": 6, + "article": "_", + "name": "\"Глаголик\" малиновый", + "uri": "/products/6", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 1 + }, + { + "id": 7, + "article": "_", + "name": "\"Глаголик\" топленое молоко", + "uri": "/products/7", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 1 + }, + { + "id": 8, + "article": "_", + "name": "\"Глаголик\" корица", + "uri": "/products/8", + "images": [], + "description": "", + "group": 1, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 1 + }, + { + "id": 9, + "article": "_", + "name": "Печенье \"Овсянка\"", + "uri": "/products/9", + "images": [], + "description": "", + "group": 2, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 10, + "article": "_", + "name": "Печенье \"Овсянка\" лимонная", + "uri": "/products/10", + "images": [], + "description": "", + "group": 2, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 11, + "article": "_", + "name": "Печенье \"Овсянка\" фисташковая", + "uri": "/products/11", + "images": [], + "description": "", + "group": 2, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 12, + "article": "_", + "name": "Печенье \"Овсянка\" шоколадная", + "uri": "/products/12", + "images": [], + "description": "", + "group": 2, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 17000, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 13, + "article": "_", + "name": "Турецкое печенье \"Амири\" с кунжутом", + "uri": "/products/13", + "images": [], + "description": "", + "group": 3, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 14, + "article": "_", + "name": "Турецкое печенье \"Амири\" с фисташковым вкусом", + "uri": "/products/14", + "images": [], + "description": "", + "group": 3, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 15, + "article": "_", + "name": "Турецкое печенье \"Амири\" семечка", + "uri": "/products/15", + "images": [], + "description": "", + "group": 3, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 16, + "article": "_", + "name": "Печенье \"Манго\"", + "uri": "/products/16", + "images": [], + "description": "", + "group": 4, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 17, + "article": "_", + "name": "Печеннье\"Красный бархат\"", + "uri": "/products/17", + "images": [], + "description": "", + "group": 5, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 16500, + "properties": [ + { + "name": "min", + "value": "0" + }, + { + "name": "max", + "value": "5" + } + ] + }, + { + "price": 16000, + "properties": [ + { + "name": "min", + "value": "6" + }, + { + "name": "max", + "value": "60" + } + ] + }, + { + "price": 15500, + "properties": [ + { + "name": "min", + "value": "61" + } + ] + } + ], + "characteristics": [], + "category": 2 + }, + { + "id": 18, + "article": "_", + "name": "Печенье \"Сказка\" с лимонным вкусом", + "uri": "/products/18", + "images": [], + "description": "", + "group": 6, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 18000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 19, + "article": "_", + "name": "Печенье \"Сказка\" с клубничным вкусом", + "uri": "/products/19", + "images": [], + "description": "", + "group": 6, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 18000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 20, + "article": "_", + "name": "Печенье \"Ромашка\"", + "uri": "/products/20", + "images": [], + "description": "", + "group": 7, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 18000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 21, + "article": "_", + "name": "Печенье \"Курабье\"", + "uri": "/products/21", + "images": [], + "description": "", + "group": 8, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 18000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 22, + "article": "_", + "name": "Печенье \"Мозайка\"", + "uri": "/products/22", + "images": [], + "description": "", + "group": 9, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 18000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 23, + "article": "_", + "name": "Пахлава ореховая контейнер 350г", + "uri": "/products/23", + "images": [], + "description": "", + "group": 10, "unit": "piece", "inventory": 100, + "variants": [ + { + "price": 11000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 24, + "article": "_", + "name": "Пахлава ореховая экран 1,5кг", + "uri": "/products/24", + "images": [], + "description": "", + "group": 10, + "unit": "kg", + "inventory": 100, "variants": [ { "price": 29000, @@ -94,12 +1014,103 @@ ] } ], - "characteristics": [ + "characteristics": [], + "category": 3 + }, + { + "id": 25, + "article": "_", + "name": "Пахлава фисташковая контейнер 350г", + "uri": "/products/25", + "images": [], + "description": "", + "group": 10, + "unit": "piece", + "inventory": 100, + "variants": [ { - "name": "Вкус", - "value": "Ореховая" + "price": 12000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] } ], - "category": 2 + "characteristics": [], + "category": 3 + }, + { + "id": 26, + "article": "_", + "name": "Пахлава фисташковая экран 1,5кг", + "uri": "/products/26", + "images": [], + "description": "", + "group": 10, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 30000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 27, + "article": "_", + "name": "Гата контейнер 350г", + "uri": "/products/27", + "images": [], + "description": "", + "group": 11, + "unit": "piece", + "inventory": 100, + "variants": [ + { + "price": 11000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 + }, + { + "id": 28, + "article": "_", + "name": "Гата экран 2,5кг", + "uri": "/products/28", + "images": [], + "description": "", + "group": 11, + "unit": "kg", + "inventory": 100, + "variants": [ + { + "price": 26000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [], + "category": 3 } ]