From 00f28e3f7b248736bedf4ef74bf92b216ad9a5ee Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Mon, 13 May 2024 04:07:25 +0700 Subject: [PATCH] init --- .gitignore | 1 + cmd/cake_crm/main.go | 10 ++ go.mod | 3 + internal/models/storage/interface.go | 20 +++ .../models/storage/storage_file/storage.go | 31 +++++ resources/db.json | 126 ++++++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/cake_crm/main.go create mode 100644 go.mod create mode 100644 internal/models/storage/interface.go create mode 100644 internal/models/storage/storage_file/storage.go create mode 100644 resources/db.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/cmd/cake_crm/main.go b/cmd/cake_crm/main.go new file mode 100644 index 0000000..15ae042 --- /dev/null +++ b/cmd/cake_crm/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "cake_crm/internal/models/storage/storage_file" +) + +func main() { + storage := storage_file.NewStorageFile("resources/db.json") + _ = storage +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bed3259 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module cake_crm + +go 1.22 diff --git a/internal/models/storage/interface.go b/internal/models/storage/interface.go new file mode 100644 index 0000000..2dce758 --- /dev/null +++ b/internal/models/storage/interface.go @@ -0,0 +1,20 @@ +package storage + +import "context" + +type Product struct { + ID int `json:"id"` + Name string `json:"name"` + // todo +} + +type Breadcrumb struct { + Name string `json:"name"` + URL string `json:"url"` +} + +type IStorage interface { + GetAllProducts(ctx context.Context) ([]Product, error) + GetProductByID(ctx context.Context, id int) (Product, error) + GetBreadcrumbs(ctx context.Context, id int) ([]Breadcrumb, error) +} diff --git a/internal/models/storage/storage_file/storage.go b/internal/models/storage/storage_file/storage.go new file mode 100644 index 0000000..e34592d --- /dev/null +++ b/internal/models/storage/storage_file/storage.go @@ -0,0 +1,31 @@ +package storage_file + +import ( + "cake_crm/internal/models/storage" + "context" +) + +type storageFile struct { + filepath string +} + +func NewStorageFile(filepath string) storage.IStorage { + return &storageFile{ + filepath: filepath, + } +} + +func (s *storageFile) GetAllProducts(ctx context.Context) ([]storage.Product, error) { + //TODO implement me + panic("implement me") +} + +func (s *storageFile) GetProductByID(ctx context.Context, id int) (storage.Product, error) { + //TODO implement me + panic("implement me") +} + +func (s *storageFile) GetBreadcrumbs(ctx context.Context, id int) ([]storage.Breadcrumb, error) { + //TODO implement me + panic("implement me") +} diff --git a/resources/db.json b/resources/db.json new file mode 100644 index 0000000..85b8a90 --- /dev/null +++ b/resources/db.json @@ -0,0 +1,126 @@ +{ + "products": [ + { + "id": 1, + "name": "\"Глаголик\" ванильно-сливочный", + "url": "/products/1", + "images": [ + "/products/1/image-1-600x600.jpg", + "/products/1/image-2-600x600.jpg", + "/products/1/image-3-600x600.jpg" + ], + "description": "", + "grouped_products": [ + { + "name": "\"Глаголик\" лимонный", + "url": "/products/2", + "image": "/products/2/image-100x100.jpg" + }, + { + "name": "\"Глаголик\" мятный", + "url": "/products/3", + "image": "/products/3/image-100x100.jpg" + } + ], + "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": [ + { + "name": "Вкус", + "value": "Ванильно-сливочный" + } + ], + "category": "1" + }, + { + "id": 4, + "name": "Пахлава ореховая экран 1,5 кг", + "url": "/products/4", + "images": [ + "/products/4/image-1-600x600.jpg", + "/products/4/image-2-600x600.jpg", + "/products/4/image-3-600x600.jpg" + ], + "description": "", + "grouped_products": [], + "unit": "piece", + "inventory": 100, + "variants": [ + { + "price": 29000, + "properties": [ + { + "name": "min", + "value": "0" + } + ] + } + ], + "characteristics": [ + { + "name": "Вкус", + "value": "Ореховая" + } + ], + "category": "2" + } + ], + "categories": [ + { + "id": 0, + "name": "Главная", + "url": "/categories/0", + "children": [ + { + "id": 1, + "name": "Пряники", + "url": "/categories/1", + "children": [] + }, + { + "id": 2, + "name": "Пахлава", + "url": "/categories/2", + "children": [] + } + ] + } + ] +}