| 283 | } |
| 284 | |
| 285 | func (i *imlImportConfigController) importCatalogues(ctx context.Context) error { |
| 286 | data, err := unmarshal[catalogue_dto.ExportCatalogue]("catalogue") |
| 287 | if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | for _, d := range data { |
| 291 | _, err = i.catalogueModule.Get(ctx, d.Id) |
| 292 | if err != nil { |
| 293 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 294 | return err |
| 295 | } |
| 296 | err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{ |
| 297 | Id: d.Id, |
| 298 | Name: d.Name, |
| 299 | Parent: &d.Parent, |
| 300 | Sort: &d.Sort, |
| 301 | }) |
| 302 | if err != nil { |
| 303 | return fmt.Errorf("create catalogue(%s) error: %v", d.Id, err) |
| 304 | } |
| 305 | continue |
| 306 | } |
| 307 | err = i.catalogueModule.Edit(ctx, d.Id, &catalogue_dto.EditCatalogue{ |
| 308 | Name: &d.Name, |
| 309 | Parent: &d.Parent, |
| 310 | Sort: &d.Sort, |
| 311 | }) |
| 312 | if err != nil { |
| 313 | return fmt.Errorf("update catalogue(%s) error: %v", d.Id, err) |
| 314 | } |
| 315 | |
| 316 | } |
| 317 | return nil |
| 318 | } |
| 319 | |
| 320 | func (i *imlImportConfigController) importUpstreams(ctx context.Context) error { |
| 321 | data, err := unmarshal[upstream_dto.ExportUpstream]("upstream") |