added paginator for GetLcr

This commit is contained in:
Radu Ioan Fericean
2015-08-04 19:29:17 +03:00
parent 41c76cc85f
commit c80a6d7857
3 changed files with 11 additions and 3 deletions

View File

@@ -779,7 +779,7 @@ func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
return nil, utils.ErrNotFound
}
func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
func (cd *CallDescriptor) GetLCR(stats StatsInterface, p *utils.Paginator) (*LCRCost, error) {
cd.account = nil // make sure it's not cached
lcr, err := cd.GetLCRFromStorage()
if err != nil {
@@ -1111,5 +1111,13 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
// sort according to strategy
lcrCost.Sort()
}
if p != nil {
if p.Offset != nil && *p.Offset > 0 && *p.Offset < len(lcrCost.SupplierCosts)-1 {
lcrCost.SupplierCosts = lcrCost.SupplierCosts[*p.Offset:]
}
if p.Limit != nil && *p.Limit > 0 && *p.Limit < len(lcrCost.SupplierCosts)-1 {
lcrCost.SupplierCosts = lcrCost.SupplierCosts[:*p.Limit]
}
}
return lcrCost, nil
}

View File

@@ -204,7 +204,7 @@ func TestLcrGet(t *testing.T) {
Account: "rif",
Subject: "rif",
}
lcr, err := cd.GetLCR(nil)
lcr, err := cd.GetLCR(nil, nil)
//jsn, _ := json.Marshal(lcr)
//log.Print("LCR: ", string(jsn))
if err != nil || lcr == nil {

View File

@@ -335,7 +335,7 @@ func (rs *Responder) GetLCR(cd *CallDescriptor, reply *LCRCost) error {
udRcv := upData.(*CallDescriptor)
*cd = *udRcv
}
lcrCost, err := cd.GetLCR(rs.Stats)
lcrCost, err := cd.GetLCR(rs.Stats, nil)
if err != nil {
return err
}