diff --git a/controllers/importer.go b/controllers/importer.go index 4cb8ada..5dc3471 100644 --- a/controllers/importer.go +++ b/controllers/importer.go @@ -66,6 +66,13 @@ func Start(w http.ResponseWriter, route *http.Request) { mainImportWG.Add(len(mainCategories)) + errDel := deleteProducts() + + if errDel != nil { + http.Error(w, errDel.Error(), http.StatusInternalServerError) + return + } + for _, element := range mainCategories { slug := element.Translations[0].Slug @@ -81,12 +88,14 @@ func Start(w http.ResponseWriter, route *http.Request) { } -func deleteProducts() { +func deleteProducts() error { //todo delete non ordered & non favorited products //select distinct ordered and favorited product ids //todo delete from elastico //Delete from products where id in (select distinct) + return baza.Delete(&gm.Product{}).Error + } func startImport(dbName string, db *gorm.DB) {