fix
This commit is contained in:
parent
67d79b7725
commit
42fbbb2ae4
@ -3,23 +3,10 @@ package seeds
|
||||
import (
|
||||
"log"
|
||||
"online-order/entity"
|
||||
repository_product "online-order/repository/product"
|
||||
repository_product_category "online-order/repository/product_category"
|
||||
service_product "online-order/usecase/product"
|
||||
service_product_category "online-order/usecase/product_category"
|
||||
)
|
||||
|
||||
func fetchProductsFromJsonFile() *[]entity.ProductCreateUpdate {
|
||||
file := CreateFile("database/seeds/resources/products.json")
|
||||
pl := []entity.ProductCreateUpdate{}
|
||||
|
||||
if err := file.ReadJson(&pl); err != nil {
|
||||
log.Println("on FillProducts an error occured: ", err)
|
||||
return nil
|
||||
}
|
||||
return &pl
|
||||
}
|
||||
|
||||
func fetchProductCategoriesFromJsonFile() *[]entity.ProductCategoryCreateUpdate {
|
||||
file := CreateFile("database/seeds/resources/categories.json")
|
||||
pl := []entity.ProductCategoryCreateUpdate{}
|
||||
@ -47,21 +34,3 @@ func FillProductCategories(server *entity.Routers) {
|
||||
productCategoryService.SyncWithSlug(item.Slug, &item)
|
||||
}
|
||||
}
|
||||
|
||||
func FillProducts(server *entity.Routers) {
|
||||
products := fetchProductsFromJsonFile()
|
||||
|
||||
activeBusiness := entity.ActiveBusiness{
|
||||
BusinessID: 1,
|
||||
DomainID: 1,
|
||||
Domain: "localhost",
|
||||
}
|
||||
|
||||
productRepo := repository_product.NewProductRepository(server.Database, &activeBusiness)
|
||||
|
||||
productService := service_product.NewProductService(productRepo)
|
||||
|
||||
for _, item := range *products {
|
||||
productService.Create(&item)
|
||||
}
|
||||
}
|
37
database/seeds/products.go
Normal file
37
database/seeds/products.go
Normal file
@ -0,0 +1,37 @@
|
||||
package seeds
|
||||
|
||||
import (
|
||||
"log"
|
||||
"online-order/entity"
|
||||
repository_product "online-order/repository/product"
|
||||
service_product "online-order/usecase/product"
|
||||
)
|
||||
|
||||
func fetchProductsFromJsonFile() *[]entity.ProductCreateUpdate {
|
||||
file := CreateFile("database/seeds/resources/products.json")
|
||||
pl := []entity.ProductCreateUpdate{}
|
||||
|
||||
if err := file.ReadJson(&pl); err != nil {
|
||||
log.Println("on FillProducts an error occured: ", err)
|
||||
return nil
|
||||
}
|
||||
return &pl
|
||||
}
|
||||
|
||||
func FillProducts(server *entity.Routers) {
|
||||
products := fetchProductsFromJsonFile()
|
||||
|
||||
activeBusiness := entity.ActiveBusiness{
|
||||
BusinessID: 1,
|
||||
DomainID: 1,
|
||||
Domain: "localhost",
|
||||
}
|
||||
|
||||
productRepo := repository_product.NewProductRepository(server.Database, &activeBusiness)
|
||||
|
||||
productService := service_product.NewProductService(productRepo)
|
||||
|
||||
for _, item := range *products {
|
||||
productService.Create(&item)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user