This commit is contained in:
Владимир Фёдоров 2024-05-13 04:07:25 +07:00
commit 00f28e3f7b
6 changed files with 191 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

10
cmd/cake_crm/main.go Normal file
View File

@ -0,0 +1,10 @@
package main
import (
"cake_crm/internal/models/storage/storage_file"
)
func main() {
storage := storage_file.NewStorageFile("resources/db.json")
_ = storage
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module cake_crm
go 1.22

View File

@ -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)
}

View File

@ -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")
}

126
resources/db.json Normal file
View File

@ -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": []
}
]
}
]
}