mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added sars model,tp,api
This commit is contained in:
committed by
Dan Christian Bogos
parent
9d7fcdc0c6
commit
6c2fbbec28
@@ -598,6 +598,27 @@ func (sqls *SQLStorage) SetTPSags(sgs []*utils.TPSagsProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sqls *SQLStorage) SetTPSars(srs []*utils.TPSarsProfile) error {
|
||||
if len(srs) == 0 {
|
||||
return nil
|
||||
}
|
||||
tx := sqls.db.Begin()
|
||||
for _, sg := range srs {
|
||||
if err := tx.Where(&SarsMdl{Tpid: sg.TPid, ID: sg.ID}).Delete(SarsMdl{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, msg := range APItoModelSars(sg) {
|
||||
if err := tx.Create(&msg).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sqls *SQLStorage) SetTPThresholds(ths []*utils.TPThresholdProfile) error {
|
||||
if len(ths) == 0 {
|
||||
return nil
|
||||
@@ -1440,6 +1461,25 @@ func (sqls *SQLStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf
|
||||
return asts, nil
|
||||
}
|
||||
|
||||
func (sqls *SQLStorage) GetTPSars(tpid, tenant, id string) ([]*utils.TPSarsProfile, error) {
|
||||
var srs SarsMdls
|
||||
q := sqls.db.Where("tpid = ?", tpid)
|
||||
if len(id) != 0 {
|
||||
q = q.Where("id = ?", id)
|
||||
}
|
||||
if len(tenant) != 0 {
|
||||
q = q.Where("tenant = ?", tenant)
|
||||
}
|
||||
if err := q.Find(&srs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
asrs := srs.AsTPSars()
|
||||
if len(asrs) == 0 {
|
||||
return asrs, utils.ErrNotFound
|
||||
}
|
||||
return asrs, nil
|
||||
}
|
||||
|
||||
func (sqls *SQLStorage) GetTPSags(tpid string, tenant string, id string) ([]*utils.TPSagsProfile, error) {
|
||||
var sgs SagsMdls
|
||||
q := sqls.db.Where("tpid = ?", tpid)
|
||||
|
||||
Reference in New Issue
Block a user