Finished implementing TPRateProfile APIs

This commit is contained in:
DanB
2013-07-12 08:40:28 +02:00
parent 7b1b278c87
commit b7c6314a09
3 changed files with 63 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ func (self *Apier) GetTPRateProfile(attrs AttrGetTPRateProfile, reply *utils.TPR
}
// Queries RateProfile identities on specific tariff plan.
func (self *Apier) GetTPRateProfiles(attrs utils.AttrTPRateProfileIds, reply *[]string) error {
func (self *Apier) GetTPRateProfileIds(attrs utils.AttrTPRateProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}

View File

@@ -444,11 +444,70 @@ func (self *SQLStorage) SetTPRateProfile(rp *utils.TPRateProfile) error {
}
func (self *SQLStorage) GetTPRateProfile(tpid, rpId string) (*utils.TPRateProfile, error) {
return nil, nil
rows, err := self.Db.Query(fmt.Sprintf("SELECT tenant,tor,direction,subject,activation_time,destrates_timing_tag,rates_fallback_subject FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_RATE_PROFILES, tpid, rpId))
if err != nil {
return nil, err
}
defer rows.Close()
rp := &utils.TPRateProfile{TPid: tpid, RateProfileId: rpId}
i := 0
for rows.Next() {
i++ //Keep here a reference so we know we got at least one result
var tenant, tor, direction, subject, drtId, fallbackSubj string
var aTime int64
err = rows.Scan(&tenant, &tor, &direction, &subject, &aTime, &drtId, &fallbackSubj)
if err != nil {
return nil, err
}
if i == 1 { // Save some info on first iteration
rp.Tenant = tenant
rp.TOR = tor
rp.Direction = direction
rp.Subject = subject
rp.RatesFallbackSubject = fallbackSubj
}
rp.RatingActivations = append(rp.RatingActivations, utils.RatingActivation{aTime, drtId})
}
if i == 0 {
return nil, nil
}
return rp, nil
}
func (self *SQLStorage) GetTPRateProfileIds(filters *utils.AttrTPRateProfileIds) ([]string, error) {
return nil, nil
qry := fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_RATE_PROFILES, filters.TPid)
if filters.Tenant != "" {
qry += fmt.Sprintf(" AND tenant='%s'", filters.Tenant)
}
if filters.TOR != "" {
qry += fmt.Sprintf(" AND tor='%s'", filters.TOR)
}
if filters.Direction != "" {
qry += fmt.Sprintf(" AND direction='%s'", filters.Direction)
}
if filters.Subject != "" {
qry += fmt.Sprintf(" AND subject='%s'", filters.Subject)
}
rows, err := self.Db.Query(qry)
if err != nil {
return nil, err
}
defer rows.Close()
ids := []string{}
i := 0
for rows.Next() {
i++ //Keep here a reference so we know we got at least one
var id string
err = rows.Scan(&id)
if err != nil {
return nil, err
}
ids = append(ids, id)
}
if i == 0 {
return nil, nil
}
return ids, nil
}
func (self *SQLStorage) GetActions(string) (as Actions, err error) {

View File

@@ -69,7 +69,7 @@ type TPRateProfile struct {
}
type RatingActivation struct {
ActivationTime int64 // Time when this profile will become active
ActivationTime int64 // Time when this profile will become active, defined as unix epoch time
DestRateTimingId string // Id of DestRateTiming profile
}