This commit is contained in:
saeid_01 2023-11-10 14:14:34 +03:30
parent 67d79b7725
commit 42fbbb2ae4
2 changed files with 37 additions and 31 deletions

View File

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

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