mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
Completed ExportToFolder from APier with AccountProfile
This commit is contained in:
committed by
Dan Christian Bogos
parent
594f7bb557
commit
87fe8ebd91
@@ -1961,6 +1961,43 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st
|
||||
}
|
||||
}
|
||||
csvWriter.Flush()
|
||||
case utils.MetaAccountProfiles:
|
||||
prfx := utils.AccountProfilePrefix
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
continue
|
||||
}
|
||||
f, err := os.Create(path.Join(arg.Path, utils.AccountProfilesCsv))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
csvWriter := csv.NewWriter(f)
|
||||
csvWriter.Comma = utils.CSVSep
|
||||
//write the header of the file
|
||||
if err := csvWriter.Write(engine.AccountProfileMdls{}.CSVHeader()); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range keys {
|
||||
tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
|
||||
accPrf, err := apierSv1.DataManager.GetAccountProfile(tntID[0], tntID[1],
|
||||
true, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, model := range engine.APItoModelTPAccountProfile(engine.AccountProfileToAPI(accPrf)) {
|
||||
if record, err := engine.CsvDump(model); err != nil {
|
||||
return err
|
||||
} else if err := csvWriter.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
csvWriter.Flush()
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user