From 8e5ea6884ef70bfe791a2f481b9ceaa33b22d382 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 2 Apr 2020 18:03:22 +0300 Subject: [PATCH] Updated TP APIs --- apier/v1/tpaccountactions.go | 59 ++++++++++++------------ apier/v1/tpactionplans.go | 37 ++++++++-------- apier/v1/tpactions.go | 37 ++++++++-------- apier/v1/tpattributes.go | 42 +++++++++--------- apier/v1/tpattributes_it_test.go | 2 +- apier/v1/tpchargers.go | 37 ++++++++-------- apier/v1/tpchargers_it_test.go | 2 +- apier/v1/tpdestinationrates.go | 37 ++++++++-------- apier/v1/tpdestinations.go | 51 ++++++++++----------- apier/v1/tpdispatchers.go | 74 +++++++++++++++---------------- apier/v1/tpdispatchers_it_test.go | 6 +-- apier/v1/tpfilters.go | 37 ++++++++-------- apier/v1/tpfilters_it_test.go | 2 +- apier/v1/tprates.go | 37 ++++++++-------- apier/v1/tpratingplans.go | 37 ++++++++-------- apier/v1/tpresources.go | 37 ++++++++-------- apier/v1/tpsharedgroups.go | 37 ++++++++-------- apier/v1/tpstats.go | 37 ++++++++-------- apier/v1/tpsuppliers.go | 37 ++++++++-------- apier/v1/tpsuppliers_it_test.go | 2 +- apier/v1/tpthresholds.go | 37 ++++++++-------- apier/v1/tpthresholds_it_test.go | 2 +- apier/v1/tptimings.go | 37 ++++++++-------- engine/storage_sql.go | 6 +-- migrator/tp_chargers.go | 23 +++++----- migrator/tp_dispatchers.go | 23 +++++----- migrator/tp_filters.go | 23 +++++----- migrator/tp_resources.go | 23 +++++----- migrator/tp_stats.go | 24 +++++----- migrator/tp_suppliers.go | 26 +++++------ migrator/tp_thresholds.go | 24 +++++----- 31 files changed, 435 insertions(+), 460 deletions(-) diff --git a/apier/v1/tpaccountactions.go b/apier/v1/tpaccountactions.go index 20fb75b92..f2419f561 100644 --- a/apier/v1/tpaccountactions.go +++ b/apier/v1/tpaccountactions.go @@ -23,13 +23,13 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new AccountActions profile within a tariff plan -func (self *APIerSv1) SetTPAccountActions(attrs utils.TPAccountActions, reply *string) error { +// SetTPAccountActions creates a new AccountActions profile within a tariff plan +func (apiv1 *APIerSv1) SetTPAccountActions(attrs utils.TPAccountActions, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Account", "ActionPlanId"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPAccountActions([]*utils.TPAccountActions{&attrs}); err != nil { + if err := apiv1.StorDb.SetTPAccountActions([]*utils.TPAccountActions{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -41,8 +41,8 @@ type AttrGetTPAccountActionsByLoadId struct { LoadId string // AccountActions id } -// Queries specific AccountActions profile on tariff plan -func (self *APIerSv1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, reply *[]*utils.TPAccountActions) error { +// GetTPAccountActionsByLoadId queries specific AccountActions profile on tariff plan +func (apiv1 *APIerSv1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, reply *[]*utils.TPAccountActions) error { mndtryFlds := []string{"TPid", "LoadId"} if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory mndtryFlds = append(mndtryFlds, "Tenant", "Account") @@ -50,14 +50,14 @@ func (self *APIerSv1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if aas, err := self.StorDb.GetTPAccountActions(&attrs); err != nil { + aas, err := apiv1.StorDb.GetTPAccountActions(&attrs) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = aas } + *reply = aas return nil } @@ -66,8 +66,8 @@ type AttrGetTPAccountActions struct { AccountActionsId string // DerivedCharge id } -// Queries specific DerivedCharge on tariff plan -func (self *APIerSv1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.TPAccountActions) error { +// GetTPAccountActions queries specific DerivedCharge on tariff plan +func (apiv1 *APIerSv1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.TPAccountActions) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -75,14 +75,14 @@ func (self *APIerSv1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply * if err := filter.SetAccountActionsId(attrs.AccountActionsId); err != nil { return err } - if aas, err := self.StorDb.GetTPAccountActions(filter); err != nil { + aas, err := apiv1.StorDb.GetTPAccountActions(filter) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *aas[0] } + *reply = *aas[0] return nil } @@ -91,42 +91,42 @@ type AttrGetTPAccountActionIds struct { utils.PaginatorWithSearch } -// Queries AccountActions identities on specific tariff plan. -func (self *APIerSv1) GetTPAccountActionLoadIds(attrs AttrGetTPAccountActionIds, reply *[]string) error { +// GetTPAccountActionLoadIds queries AccountActions identities on specific tariff plan. +func (apiv1 *APIerSv1) GetTPAccountActionLoadIds(attrs AttrGetTPAccountActionIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, - utils.TPDistinctIds{"loadid"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := apiv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, + utils.TPDistinctIds{"loadid"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Queries DerivedCharges identities on specific tariff plan. -func (self *APIerSv1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, reply *[]string) error { +// GetTPAccountActionIds queries DerivedCharges identities on specific tariff plan. +func (apiv1 *APIerSv1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, - utils.TPDistinctIds{"loadid", "tenant", "account"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := apiv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccountActions, + utils.TPDistinctIds{"loadid", "tenant", "account"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific AccountActions on Tariff plan -func (self *APIerSv1) RemoveTPAccountActions(attrs AttrGetTPAccountActions, reply *string) error { +// RemoveTPAccountActions removes specific AccountActions on Tariff plan +func (apiv1 *APIerSv1) RemoveTPAccountActions(attrs AttrGetTPAccountActions, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Account"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -134,11 +134,10 @@ func (self *APIerSv1) RemoveTPAccountActions(attrs AttrGetTPAccountActions, repl if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil { return err } - if err := self.StorDb.RemTpData(utils.TBLTPAccountActions, aa.Tpid, + if err := apiv1.StorDb.RemTpData(utils.TBLTPAccountActions, aa.Tpid, map[string]string{"loadid": aa.Loadid, "tenant": aa.Tenant, "account": aa.Account}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpactionplans.go b/apier/v1/tpactionplans.go index 57a0b6c5b..ef790874e 100644 --- a/apier/v1/tpactionplans.go +++ b/apier/v1/tpactionplans.go @@ -24,8 +24,8 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new ActionTimings profile within a tariff plan -func (self *APIerSv1) SetTPActionPlan(attrs utils.TPActionPlan, reply *string) error { +// SetTPActionPlan creates a new ActionTimings profile within a tariff plan +func (apiv1 *APIerSv1) SetTPActionPlan(attrs utils.TPActionPlan, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "ActionPlan"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -35,7 +35,7 @@ func (self *APIerSv1) SetTPActionPlan(attrs utils.TPActionPlan, reply *string) e return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), at.ActionsId, missing) } } - if err := self.StorDb.SetTPActionPlans([]*utils.TPActionPlan{&attrs}); err != nil { + if err := apiv1.StorDb.SetTPActionPlans([]*utils.TPActionPlan{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -47,19 +47,19 @@ type AttrGetTPActionPlan struct { ID string // ActionPlans id } -// Queries specific ActionPlan profile on tariff plan -func (self *APIerSv1) GetTPActionPlan(attrs AttrGetTPActionPlan, reply *utils.TPActionPlan) error { +// GetTPActionPlan queries specific ActionPlan profile on tariff plan +func (apiv1 *APIerSv1) GetTPActionPlan(attrs AttrGetTPActionPlan, reply *utils.TPActionPlan) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if aps, err := self.StorDb.GetTPActionPlans(attrs.TPid, attrs.ID); err != nil { + aps, err := apiv1.StorDb.GetTPActionPlans(attrs.TPid, attrs.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *aps[0] } + *reply = *aps[0] return nil } @@ -68,33 +68,32 @@ type AttrGetTPActionPlanIds struct { utils.PaginatorWithSearch } -// Queries ActionPlan identities on specific tariff plan. -func (self *APIerSv1) GetTPActionPlanIds(attrs AttrGetTPActionPlanIds, reply *[]string) error { +// GetTPActionPlanIds queries ActionPlan identities on specific tariff plan. +func (apiv1 *APIerSv1) GetTPActionPlanIds(attrs AttrGetTPActionPlanIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionPlans, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := apiv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionPlans, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific ActionPlan on Tariff plan -func (self *APIerSv1) RemoveTPActionPlan(attrs AttrGetTPActionPlan, reply *string) error { +// RemoveTPActionPlan removes specific ActionPlan on Tariff plan +func (apiv1 *APIerSv1) RemoveTPActionPlan(attrs AttrGetTPActionPlan, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPActionPlans, + if err := apiv1.StorDb.RemTpData(utils.TBLTPActionPlans, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpactions.go b/apier/v1/tpactions.go index 5603a8b32..e8fec8311 100644 --- a/apier/v1/tpactions.go +++ b/apier/v1/tpactions.go @@ -22,12 +22,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new Actions profile within a tariff plan -func (self *APIerSv1) SetTPActions(attrs utils.TPActions, reply *string) error { +// SetTPActions creates a new Actions profile within a tariff plan +func (apiv1 *APIerSv1) SetTPActions(attrs utils.TPActions, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "Actions"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPActions([]*utils.TPActions{&attrs}); err != nil { + if err := apiv1.StorDb.SetTPActions([]*utils.TPActions{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -39,19 +39,19 @@ type AttrGetTPActions struct { ID string // Actions id } -// Queries specific Actions profile on tariff plan -func (self *APIerSv1) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error { +// GetTPActions queries specific Actions profile on tariff plan +func (apiv1 *APIerSv1) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if as, err := self.StorDb.GetTPActions(attrs.TPid, attrs.ID); err != nil { + as, err := apiv1.StorDb.GetTPActions(attrs.TPid, attrs.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *as[0] } + *reply = *as[0] return nil } @@ -60,33 +60,32 @@ type AttrGetTPActionIds struct { utils.PaginatorWithSearch } -// Queries Actions identities on specific tariff plan. -func (self *APIerSv1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) error { +// GetTPActionIds queries Actions identities on specific tariff plan. +func (apiv1 *APIerSv1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActions, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := apiv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActions, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Actions on Tariff plan -func (self *APIerSv1) RemoveTPActions(attrs AttrGetTPActions, reply *string) error { +// RemoveTPActions removes specific Actions on Tariff plan +func (apiv1 *APIerSv1) RemoveTPActions(attrs AttrGetTPActions, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPActions, + if err := apiv1.StorDb.RemTpData(utils.TBLTPActions, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpattributes.go b/apier/v1/tpattributes.go index 20129fee5..69b81f2f3 100644 --- a/apier/v1/tpattributes.go +++ b/apier/v1/tpattributes.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new AttributeProfile within a tariff plan -func (self *APIerSv1) SetTPAttributeProfile(attrs *utils.TPAttributeProfile, reply *string) error { +// SetTPAttributeProfile creates a new AttributeProfile within a tariff plan +func (api *APIerSv1) SetTPAttributeProfile(attrs *utils.TPAttributeProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPAttributes([]*utils.TPAttributeProfile{attrs}); err != nil { + if err := api.StorDb.SetTPAttributes([]*utils.TPAttributeProfile{attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK return nil } -// Queries specific AttributeProfile on Tariff plan -func (self *APIerSv1) GetTPAttributeProfile(attr *utils.TPTntID, reply *utils.TPAttributeProfile) error { +// GetTPAttributeProfile queries specific AttributeProfile on Tariff plan +func (api *APIerSv1) GetTPAttributeProfile(attr *utils.TPTntID, reply *utils.TPAttributeProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if als, err := self.StorDb.GetTPAttributes(attr.TPid, attr.Tenant, attr.ID); err != nil { + als, err := api.StorDb.GetTPAttributes(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *als[0] } + *reply = *als[0] return nil } @@ -55,32 +55,32 @@ type AttrGetTPAttributeProfileIds struct { utils.PaginatorWithSearch } -// Queries attribute identities on specific tariff plan. -func (self *APIerSv1) GetTPAttributeProfileIds(attrs *AttrGetTPAttributeProfileIds, reply *[]string) error { +// GetTPAttributeProfileIds queries attribute identities on specific tariff plan. +func (api *APIerSv1) GetTPAttributeProfileIds(attrs *AttrGetTPAttributeProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAttributes, - utils.TPDistinctIds{"id"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAttributes, + utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch) + if err != nil { return utils.NewErrServerError(err) - } else if ids == nil { - return utils.ErrNotFound - } else { - *reply = ids } + if ids == nil { + return utils.ErrNotFound + } + *reply = ids return nil } -// Removes specific AttributeProfile on Tariff plan -func (self *APIerSv1) RemoveTPAttributeProfile(attrs *utils.TPTntID, reply *string) error { +// RemoveTPAttributeProfile removes specific AttributeProfile on Tariff plan +func (api *APIerSv1) RemoveTPAttributeProfile(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPAttributes, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPAttributes, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go index 3138e0bb3..d5e3707ee 100644 --- a/apier/v1/tpattributes_it_test.go +++ b/apier/v1/tpattributes_it_test.go @@ -165,7 +165,7 @@ func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) { func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) { var result []string - expectedTPID := []string{"Attr1"} + expectedTPID := []string{"cgrates.org:Attr1"} if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfileIds, &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) diff --git a/apier/v1/tpchargers.go b/apier/v1/tpchargers.go index 2339ab5b5..f34419147 100755 --- a/apier/v1/tpchargers.go +++ b/apier/v1/tpchargers.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new ChargerProfile within a tariff plan -func (self *APIerSv1) SetTPCharger(attr *utils.TPChargerProfile, reply *string) error { +// SetTPCharger creates a new ChargerProfile within a tariff plan +func (api *APIerSv1) SetTPCharger(attr *utils.TPChargerProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPChargers([]*utils.TPChargerProfile{attr}); err != nil { + if err := api.StorDb.SetTPChargers([]*utils.TPChargerProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -// Queries specific ChargerProfile on Tariff plan -func (self *APIerSv1) GetTPCharger(attr *utils.TPTntID, reply *utils.TPChargerProfile) error { +// GetTPCharger queries specific ChargerProfile on Tariff plan +func (api *APIerSv1) GetTPCharger(attr *utils.TPTntID, reply *utils.TPChargerProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPChargers(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPChargers(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } @@ -55,33 +55,32 @@ type AttrGetTPChargerIds struct { utils.PaginatorWithSearch } -// Queries Charger identities on specific tariff plan. -func (self *APIerSv1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, reply *[]string) error { +// GetTPChargerIDs queries Charger identities on specific tariff plan. +func (api *APIerSv1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPChargers, utils.TPDistinctIds{"id"}, - nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPChargers, utils.TPDistinctIds{"tenant", "id"}, + nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific ChargerProfile on Tariff plan -func (self *APIerSv1) RemoveTPCharger(attrs *utils.TPTntID, reply *string) error { +// RemoveTPCharger removes specific ChargerProfile on Tariff plan +func (api *APIerSv1) RemoveTPCharger(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPChargers, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPChargers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpchargers_it_test.go b/apier/v1/tpchargers_it_test.go index ce57333e9..683718de8 100644 --- a/apier/v1/tpchargers_it_test.go +++ b/apier/v1/tpchargers_it_test.go @@ -163,7 +163,7 @@ func testTPChrgsGetTPChrgsAfterSet(t *testing.T) { func testTPChrgsGetTPChrgsIDs(t *testing.T) { var result []string - expectedTPID := []string{"Chrgs"} + expectedTPID := []string{"cgrates.org:Chrgs"} if err := tpChrgsRPC.Call(utils.APIerSv1GetTPChargerIDs, &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) diff --git a/apier/v1/tpdestinationrates.go b/apier/v1/tpdestinationrates.go index 042b1a69c..d7b77cf79 100644 --- a/apier/v1/tpdestinationrates.go +++ b/apier/v1/tpdestinationrates.go @@ -24,12 +24,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new DestinationRate profile within a tariff plan -func (self *APIerSv1) SetTPDestinationRate(attrs utils.TPDestinationRate, reply *string) error { +// SetTPDestinationRate creates a new DestinationRate profile within a tariff plan +func (api *APIerSv1) SetTPDestinationRate(attrs utils.TPDestinationRate, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "DestinationRates"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPDestinationRates([]*utils.TPDestinationRate{&attrs}); err != nil { + if err := api.StorDb.SetTPDestinationRates([]*utils.TPDestinationRate{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -42,19 +42,19 @@ type AttrGetTPDestinationRate struct { utils.Paginator } -// Queries specific DestinationRate profile on tariff plan -func (self *APIerSv1) GetTPDestinationRate(attrs AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error { +// GetTPDestinationRate queries specific DestinationRate profile on tariff plan +func (api *APIerSv1) GetTPDestinationRate(attrs AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if drs, err := self.StorDb.GetTPDestinationRates(attrs.TPid, attrs.ID, &attrs.Paginator); err != nil { + drs, err := api.StorDb.GetTPDestinationRates(attrs.TPid, attrs.ID, &attrs.Paginator) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *drs[0] } + *reply = *drs[0] return nil } @@ -63,32 +63,31 @@ type AttrTPDestinationRateIds struct { utils.PaginatorWithSearch } -// Queries DestinationRate identities on specific tariff plan. -func (self *APIerSv1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]string) error { +// GetTPDestinationRateIds queries DestinationRate identities on specific tariff plan. +func (api *APIerSv1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinationRates, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinationRates, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific DestinationRate on Tariff plan -func (self *APIerSv1) RemoveTPDestinationRate(attrs AttrGetTPDestinationRate, reply *string) error { +// RemoveTPDestinationRate removes specific DestinationRate on Tariff plan +func (api *APIerSv1) RemoveTPDestinationRate(attrs AttrGetTPDestinationRate, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPDestinationRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPDestinationRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpdestinations.go b/apier/v1/tpdestinations.go index 7bcb969e4..ce13b6b1a 100644 --- a/apier/v1/tpdestinations.go +++ b/apier/v1/tpdestinations.go @@ -22,12 +22,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new destination within a tariff plan -func (self *APIerSv1) SetTPDestination(attrs utils.TPDestination, reply *string) error { +// SetTPDestination creates a new destination within a tariff plan +func (api *APIerSv1) SetTPDestination(attrs utils.TPDestination, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "Prefixes"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPDestinations([]*utils.TPDestination{&attrs}); err != nil { + if err := api.StorDb.SetTPDestinations([]*utils.TPDestination{&attrs}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -39,20 +39,21 @@ type AttrGetTPDestination struct { ID string // Destination id } -// Queries a specific destination -func (self *APIerSv1) GetTPDestination(attrs AttrGetTPDestination, reply *utils.TPDestination) error { +// GetTPDestination queries a specific destination +func (api *APIerSv1) GetTPDestination(attrs AttrGetTPDestination, reply *utils.TPDestination) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if tpDsts, err := self.StorDb.GetTPDestinations(attrs.TPid, attrs.ID); err != nil { + tpDsts, err := api.StorDb.GetTPDestinations(attrs.TPid, attrs.ID) + if err != nil { return utils.APIErrorHandler(err) - } else if len(tpDsts) == 0 { - return utils.ErrNotFound - } else { - tpDst := tpDsts[0] - *reply = utils.TPDestination{TPid: tpDst.TPid, - ID: tpDst.ID, Prefixes: tpDst.Prefixes} } + if len(tpDsts) == 0 { + return utils.ErrNotFound + } + tpDst := tpDsts[0] + *reply = utils.TPDestination{TPid: tpDst.TPid, + ID: tpDst.ID, Prefixes: tpDst.Prefixes} return nil } @@ -61,31 +62,31 @@ type AttrGetTPDestinationIds struct { utils.PaginatorWithSearch } -// Queries destination identities on specific tariff plan. -func (self *APIerSv1) GetTPDestinationIDs(attrs AttrGetTPDestinationIds, reply *[]string) error { +// GetTPDestinationIDs queries destination identities on specific tariff plan. +func (api *APIerSv1) GetTPDestinationIDs(attrs AttrGetTPDestinationIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinations, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinations, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { return utils.APIErrorHandler(err) - } else if ids == nil { - return utils.ErrNotFound - } else { - *reply = ids } + if ids == nil { + return utils.ErrNotFound + } + *reply = ids return nil } -// Removes specific Destination on Tariff plan -func (self *APIerSv1) RemoveTPDestination(attrs AttrGetTPDestination, reply *string) error { +// RemoveTPDestination removes specific Destination on Tariff plan +func (api *APIerSv1) RemoveTPDestination(attrs AttrGetTPDestination, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.APIErrorHandler(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpdispatchers.go b/apier/v1/tpdispatchers.go index 6f37beb07..bc846d725 100644 --- a/apier/v1/tpdispatchers.go +++ b/apier/v1/tpdispatchers.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -//SetTPDispatcher creates a new DispatcherProfile within a tariff plan -func (self *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error { +// SetTPDispatcherProfile creates a new DispatcherProfile within a tariff plan +func (api *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPDispatcherProfiles([]*utils.TPDispatcherProfile{attr}); err != nil { + if err := api.StorDb.SetTPDispatcherProfiles([]*utils.TPDispatcherProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -//GetTPCharger queries specific DispatcherProfile on Tariff plan -func (self *APIerSv1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { +// GetTPDispatcherProfile queries specific DispatcherProfile on Tariff plan +func (api *APIerSv1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPDispatcherProfiles(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPDispatcherProfiles(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } @@ -55,92 +55,90 @@ type AttrGetTPDispatcherIds struct { utils.PaginatorWithSearch } -//GetTPDispatcherIDs queries dispatcher identities on specific tariff plan. -func (self *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { +// GetTPDispatcherProfileIDs queries dispatcher identities on specific tariff plan. +func (api *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatchers, utils.TPDistinctIds{"id"}, - nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatchers, utils.TPDistinctIds{"tenant", "id"}, + nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -//RemoveTPCharger removes specific DispatcherProfile on Tariff plan -func (self *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error { +// RemoveTPDispatcherProfile removes specific DispatcherProfile on Tariff plan +func (api *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPDispatchers, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPDispatchers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } -//SetTPDispatcherHost creates a new DispatcherHost within a tariff plan -func (self *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, reply *string) error { +// SetTPDispatcherHost creates a new DispatcherHost within a tariff plan +func (api *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPDispatcherHosts([]*utils.TPDispatcherHost{attr}); err != nil { + if err := api.StorDb.SetTPDispatcherHosts([]*utils.TPDispatcherHost{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -//GetTPDispatcherHost queries specific DispatcherHosts on Tariff plan -func (self *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.TPDispatcherHost) error { +// GetTPDispatcherHost queries specific DispatcherHosts on Tariff plan +func (api *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.TPDispatcherHost) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPDispatcherHosts(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPDispatcherHosts(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } -//GetTPDispatcherHostIDs queries dispatcher host identities on specific tariff plan. -func (self *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { +// GetTPDispatcherHostIDs queries dispatcher host identities on specific tariff plan. +func (api *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatcherHosts, utils.TPDistinctIds{"id"}, - nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatcherHosts, utils.TPDistinctIds{"tenant", "id"}, + nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -//RemoveTPDispatcherHost removes specific DispatcherHost on Tariff plan -func (self *APIerSv1) RemoveTPDispatcherHost(attrs *utils.TPTntID, reply *string) error { +// RemoveTPDispatcherHost removes specific DispatcherHost on Tariff plan +func (api *APIerSv1) RemoveTPDispatcherHost(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPDispatcherHosts, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPDispatcherHosts, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpdispatchers_it_test.go b/apier/v1/tpdispatchers_it_test.go index 1a5a8680a..24ad31312 100644 --- a/apier/v1/tpdispatchers_it_test.go +++ b/apier/v1/tpdispatchers_it_test.go @@ -50,7 +50,7 @@ var sTestsTPDispatchers = []func(t *testing.T){ ttestTPDispatcherGetTPDispatcherBeforeSet, testTPDispatcherSetTPDispatcher, testTPDispatcherGetTPDispatcherAfterSet, - testTPDispatcherGetFilterIds, + testTPDispatcherGetTPDispatcherIds, testTPDispatcherUpdateTPDispatcher, testTPDispatcherGetTPDispatcherAfterUpdate, testTPDispatcherRemTPDispatcher, @@ -154,9 +154,9 @@ func testTPDispatcherGetTPDispatcherAfterSet(t *testing.T) { } } -func testTPDispatcherGetFilterIds(t *testing.T) { +func testTPDispatcherGetTPDispatcherIds(t *testing.T) { var result []string - expectedTPID := []string{"Dsp1"} + expectedTPID := []string{"cgrates.org:Dsp1"} if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfileIDs, &AttrGetTPDispatcherIds{TPid: "TP1"}, &result); err != nil { t.Error(err) diff --git a/apier/v1/tpfilters.go b/apier/v1/tpfilters.go index 65c942375..940dc8618 100644 --- a/apier/v1/tpfilters.go +++ b/apier/v1/tpfilters.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new FilterProfile within a tariff plan -func (self *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply *string) error { +// SetTPFilterProfile creates a new FilterProfile within a tariff plan +func (api *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPFilters([]*utils.TPFilterProfile{attrs}); err != nil { + if err := api.StorDb.SetTPFilters([]*utils.TPFilterProfile{attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK return nil } -// Queries specific FilterProfile on tariff plan -func (self *APIerSv1) GetTPFilterProfile(attr *utils.TPTntID, reply *utils.TPFilterProfile) error { +// GetTPFilterProfile queries specific FilterProfile on tariff plan +func (api *APIerSv1) GetTPFilterProfile(attr *utils.TPTntID, reply *utils.TPFilterProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if filter, err := self.StorDb.GetTPFilters(attr.TPid, attr.Tenant, attr.ID); err != nil { + filter, err := api.StorDb.GetTPFilters(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *filter[0] } + *reply = *filter[0] return nil } @@ -55,33 +55,32 @@ type AttrGetTPFilterProfileIds struct { utils.PaginatorWithSearch } -// Queries FilterProfile identities on specific tariff plan. -func (self *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds, reply *[]string) error { +// GetTPFilterProfileIds queries FilterProfile identities on specific tariff plan. +func (api *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPFilters, utils.TPDistinctIds{"id"}, - nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPFilters, utils.TPDistinctIds{"tenant", "id"}, + nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific FilterProfile on Tariff plan -func (self *APIerSv1) RemoveTPFilterProfile(attrs *utils.TPTntID, reply *string) error { +// RemoveTPFilterProfile removes specific FilterProfile on Tariff plan +func (api *APIerSv1) RemoveTPFilterProfile(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPFilters, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPFilters, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpfilters_it_test.go b/apier/v1/tpfilters_it_test.go index 8494db9cc..7a3009b34 100644 --- a/apier/v1/tpfilters_it_test.go +++ b/apier/v1/tpfilters_it_test.go @@ -166,7 +166,7 @@ func testTPFilterGetTPFilterAfterSet(t *testing.T) { func testTPFilterGetFilterIds(t *testing.T) { var result []string - expectedTPID := []string{"Filter"} + expectedTPID := []string{"cgrates.org:Filter"} if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfileIds, &AttrGetTPFilterProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) diff --git a/apier/v1/tprates.go b/apier/v1/tprates.go index c992043fa..806cd1299 100644 --- a/apier/v1/tprates.go +++ b/apier/v1/tprates.go @@ -24,12 +24,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new rate within a tariff plan -func (self *APIerSv1) SetTPRate(attrs utils.TPRate, reply *string) error { +// SetTPRate creates a new rate within a tariff plan +func (api *APIerSv1) SetTPRate(attrs utils.TPRate, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "RateSlots"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPRates([]*utils.TPRate{&attrs}); err != nil { + if err := api.StorDb.SetTPRates([]*utils.TPRate{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -41,19 +41,19 @@ type AttrGetTPRate struct { ID string // Rate id } -// Queries specific Rate on tariff plan -func (self *APIerSv1) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error { +// GetTPRate queries specific Rate on tariff plan +func (api *APIerSv1) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rs, err := self.StorDb.GetTPRates(attrs.TPid, attrs.ID); err != nil { + rs, err := api.StorDb.GetTPRates(attrs.TPid, attrs.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rs[0] } + *reply = *rs[0] return nil } @@ -62,32 +62,31 @@ type AttrGetTPRateIds struct { utils.PaginatorWithSearch } -// Queries rate identities on specific tariff plan. -func (self *APIerSv1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error { +// GetTPRateIds queries rate identities on specific tariff plan. +func (api *APIerSv1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRates, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRates, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Rate on Tariff plan -func (self *APIerSv1) RemoveTPRate(attrs AttrGetTPRate, reply *string) error { +// RemoveTPRate removes specific Rate on Tariff plan +func (api *APIerSv1) RemoveTPRate(attrs AttrGetTPRate, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpratingplans.go b/apier/v1/tpratingplans.go index 02421efc8..65f43c5b6 100644 --- a/apier/v1/tpratingplans.go +++ b/apier/v1/tpratingplans.go @@ -24,12 +24,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new DestinationRateTiming profile within a tariff plan -func (self *APIerSv1) SetTPRatingPlan(attrs utils.TPRatingPlan, reply *string) error { +// SetTPRatingPlan creates a new DestinationRateTiming profile within a tariff plan +func (api *APIerSv1) SetTPRatingPlan(attrs utils.TPRatingPlan, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "RatingPlanBindings"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPRatingPlans([]*utils.TPRatingPlan{&attrs}); err != nil { + if err := api.StorDb.SetTPRatingPlans([]*utils.TPRatingPlan{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -42,19 +42,19 @@ type AttrGetTPRatingPlan struct { utils.Paginator } -// Queries specific RatingPlan profile on tariff plan -func (self *APIerSv1) GetTPRatingPlan(attrs AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error { +// GetTPRatingPlan queries specific RatingPlan profile on tariff plan +func (api *APIerSv1) GetTPRatingPlan(attrs AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rps, err := self.StorDb.GetTPRatingPlans(attrs.TPid, attrs.ID, &attrs.Paginator); err != nil { + rps, err := api.StorDb.GetTPRatingPlans(attrs.TPid, attrs.ID, &attrs.Paginator) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rps[0] } + *reply = *rps[0] return nil } @@ -63,32 +63,31 @@ type AttrGetTPRatingPlanIds struct { utils.PaginatorWithSearch } -// Queries RatingPlan identities on specific tariff plan. -func (self *APIerSv1) GetTPRatingPlanIds(attrs AttrGetTPRatingPlanIds, reply *[]string) error { +// GetTPRatingPlanIds queries RatingPlan identities on specific tariff plan. +func (api *APIerSv1) GetTPRatingPlanIds(attrs AttrGetTPRatingPlanIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingPlans, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingPlans, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific RatingPlan on Tariff plan -func (self *APIerSv1) RemoveTPRatingPlan(attrs AttrGetTPRatingPlan, reply *string) error { +// RemoveTPRatingPlan removes specific RatingPlan on Tariff plan +func (api *APIerSv1) RemoveTPRatingPlan(attrs AttrGetTPRatingPlan, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPRatingPlans, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPRatingPlans, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpresources.go b/apier/v1/tpresources.go index a8e9693d0..01d62758e 100644 --- a/apier/v1/tpresources.go +++ b/apier/v1/tpresources.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new resource within a tariff plan -func (self *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *string) error { +// SetTPResource creates a new resource within a tariff plan +func (api *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID", "Limit"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPResources([]*utils.TPResourceProfile{attr}); err != nil { + if err := api.StorDb.SetTPResources([]*utils.TPResourceProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -// Queries specific Resource on Tariff plan -func (self *APIerSv1) GetTPResource(attr *utils.TPTntID, reply *utils.TPResourceProfile) error { +// GetTPResource queries specific Resource on Tariff plan +func (api *APIerSv1) GetTPResource(attr *utils.TPTntID, reply *utils.TPResourceProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPResources(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPResources(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } @@ -55,33 +55,32 @@ type AttrGetTPResourceIds struct { utils.PaginatorWithSearch } -// Queries Resource identities on specific tariff plan. -func (self *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[]string) error { +// GetTPResourceIDs queries Resource identities on specific tariff plan. +func (api *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResources, - utils.TPDistinctIds{"id"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResources, + utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Resource on Tariff plan -func (self *APIerSv1) RemoveTPResource(attrs *utils.TPTntID, reply *string) error { +// RemoveTPResource removes specific Resource on Tariff plan +func (api *APIerSv1) RemoveTPResource(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpsharedgroups.go b/apier/v1/tpsharedgroups.go index e0e8d59fc..c421289d9 100644 --- a/apier/v1/tpsharedgroups.go +++ b/apier/v1/tpsharedgroups.go @@ -22,12 +22,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new SharedGroups profile within a tariff plan -func (self *APIerSv1) SetTPSharedGroups(attrs utils.TPSharedGroups, reply *string) error { +// SetTPSharedGroups creates a new SharedGroups profile within a tariff plan +func (api *APIerSv1) SetTPSharedGroups(attrs utils.TPSharedGroups, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "SharedGroups"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPSharedGroups([]*utils.TPSharedGroups{&attrs}); err != nil { + if err := api.StorDb.SetTPSharedGroups([]*utils.TPSharedGroups{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -39,19 +39,19 @@ type AttrGetTPSharedGroups struct { ID string // SharedGroup id } -// Queries specific SharedGroup on tariff plan -func (self *APIerSv1) GetTPSharedGroups(attrs AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error { +// GetTPSharedGroups queries specific SharedGroup on tariff plan +func (api *APIerSv1) GetTPSharedGroups(attrs AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if sgs, err := self.StorDb.GetTPSharedGroups(attrs.TPid, attrs.ID); err != nil { + sgs, err := api.StorDb.GetTPSharedGroups(attrs.TPid, attrs.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *sgs[0] } + *reply = *sgs[0] return nil } @@ -60,32 +60,31 @@ type AttrGetTPSharedGroupIds struct { utils.PaginatorWithSearch } -// Queries SharedGroups identities on specific tariff plan. -func (self *APIerSv1) GetTPSharedGroupIds(attrs AttrGetTPSharedGroupIds, reply *[]string) error { +// GetTPSharedGroupIds queries SharedGroups identities on specific tariff plan. +func (api *APIerSv1) GetTPSharedGroupIds(attrs AttrGetTPSharedGroupIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSharedGroups, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSharedGroups, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific SharedGroups on Tariff plan -func (self *APIerSv1) RemoveTPSharedGroups(attrs AttrGetTPSharedGroups, reply *string) error { +// RemoveTPSharedGroups removes specific SharedGroups on Tariff plan +func (api *APIerSv1) RemoveTPSharedGroups(attrs AttrGetTPSharedGroups, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPSharedGroups, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPSharedGroups, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpstats.go b/apier/v1/tpstats.go index 8f4ceaab3..de34ca879 100644 --- a/apier/v1/tpstats.go +++ b/apier/v1/tpstats.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new stat within a tariff plan -func (self *APIerSv1) SetTPStat(attr *utils.TPStatProfile, reply *string) error { +// SetTPStat creates a new stat within a tariff plan +func (api *APIerSv1) SetTPStat(attr *utils.TPStatProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPStats([]*utils.TPStatProfile{attr}); err != nil { + if err := api.StorDb.SetTPStats([]*utils.TPStatProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -// Queries specific Stat on Tariff plan -func (self *APIerSv1) GetTPStat(attr *utils.TPTntID, reply *utils.TPStatProfile) error { +// GetTPStat queries specific Stat on Tariff plan +func (api *APIerSv1) GetTPStat(attr *utils.TPTntID, reply *utils.TPStatProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPStats(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPStats(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } @@ -56,34 +56,33 @@ type AttrGetTPStatIds struct { utils.PaginatorWithSearch } -// Queries Stat identities on specific tariff plan. -func (self *APIerSv1) GetTPStatIDs(attrs *AttrGetTPStatIds, reply *[]string) error { +// GetTPStatIDs queries Stat identities on specific tariff plan. +func (api *APIerSv1) GetTPStatIDs(attrs *AttrGetTPStatIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPStats, - utils.TPDistinctIds{"id"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPStats, + utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Stat on Tariff plan -func (self *APIerSv1) RemoveTPStat(attrs *utils.TPTntID, reply *string) error { +// RemoveTPStat removes specific Stat on Tariff plan +func (api *APIerSv1) RemoveTPStat(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPStats, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPStats, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpsuppliers.go b/apier/v1/tpsuppliers.go index 8491cee78..e5555d676 100644 --- a/apier/v1/tpsuppliers.go +++ b/apier/v1/tpsuppliers.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new SupplierProfile within a tariff plan -func (self *APIerSv1) SetTPSupplierProfile(attrs *utils.TPSupplierProfile, reply *string) error { +// SetTPSupplierProfile creates a new SupplierProfile within a tariff plan +func (api *APIerSv1) SetTPSupplierProfile(attrs *utils.TPSupplierProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPSuppliers([]*utils.TPSupplierProfile{attrs}); err != nil { + if err := api.StorDb.SetTPSuppliers([]*utils.TPSupplierProfile{attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK return nil } -// Queries specific SupplierProfile on tariff plan -func (self *APIerSv1) GetTPSupplierProfile(attr *utils.TPTntID, reply *utils.TPSupplierProfile) error { +// GetTPSupplierProfile queries specific SupplierProfile on tariff plan +func (api *APIerSv1) GetTPSupplierProfile(attr *utils.TPTntID, reply *utils.TPSupplierProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if spp, err := self.StorDb.GetTPSuppliers(attr.TPid, attr.Tenant, attr.ID); err != nil { + spp, err := api.StorDb.GetTPSuppliers(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *spp[0] } + *reply = *spp[0] return nil } @@ -55,33 +55,32 @@ type AttrGetTPSupplierProfileIDs struct { utils.PaginatorWithSearch } -// Queries SupplierProfile identities on specific tariff plan. -func (self *APIerSv1) GetTPSupplierProfileIDs(attrs *AttrGetTPSupplierProfileIDs, reply *[]string) error { +// GetTPSupplierProfileIDs queries SupplierProfile identities on specific tariff plan. +func (api *APIerSv1) GetTPSupplierProfileIDs(attrs *AttrGetTPSupplierProfileIDs, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSuppliers, - utils.TPDistinctIds{"id"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSuppliers, + utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific SupplierProfile on Tariff plan -func (self *APIerSv1) RemoveTPSupplierProfile(attrs *utils.TPTntID, reply *string) error { +// RemoveTPSupplierProfile removes specific SupplierProfile on Tariff plan +func (api *APIerSv1) RemoveTPSupplierProfile(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPSuppliers, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPSuppliers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpsuppliers_it_test.go b/apier/v1/tpsuppliers_it_test.go index 2eba96869..9662355d0 100644 --- a/apier/v1/tpsuppliers_it_test.go +++ b/apier/v1/tpsuppliers_it_test.go @@ -175,7 +175,7 @@ func testTPSplPrfGetTPSplPrfAfterSet(t *testing.T) { func testTPSplPrfGetTPSplPrfIDs(t *testing.T) { var result []string - expectedTPID := []string{"SUPL_1"} + expectedTPID := []string{"cgrates.org:SUPL_1"} if err := tpSplPrfRPC.Call(utils.APIerSv1GetTPSupplierProfileIDs, &AttrGetTPSupplierProfileIDs{TPid: "TP1"}, &result); err != nil { t.Error(err) diff --git a/apier/v1/tpthresholds.go b/apier/v1/tpthresholds.go index 721ad58d2..619f5fe6b 100644 --- a/apier/v1/tpthresholds.go +++ b/apier/v1/tpthresholds.go @@ -22,31 +22,31 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new threshold within a tariff plan -func (self *APIerSv1) SetTPThreshold(attr *utils.TPThresholdProfile, reply *string) error { +// SetTPThreshold creates a new threshold within a tariff plan +func (api *APIerSv1) SetTPThreshold(attr *utils.TPThresholdProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPThresholds([]*utils.TPThresholdProfile{attr}); err != nil { + if err := api.StorDb.SetTPThresholds([]*utils.TPThresholdProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK return nil } -// Queries specific Threshold on Tariff plan -func (self *APIerSv1) GetTPThreshold(attr *utils.TPTntID, reply *utils.TPThresholdProfile) error { +// GetTPThreshold queries specific Threshold on Tariff plan +func (api *APIerSv1) GetTPThreshold(attr *utils.TPTntID, reply *utils.TPThresholdProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPThresholds(attr.TPid, attr.Tenant, attr.ID); err != nil { + rls, err := api.StorDb.GetTPThresholds(attr.TPid, attr.Tenant, attr.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *rls[0] } + *reply = *rls[0] return nil } @@ -56,34 +56,33 @@ type AttrGetTPThresholdIds struct { utils.PaginatorWithSearch } -// Queries Threshold identities on specific tariff plan. -func (self *APIerSv1) GetTPThresholdIDs(attrs *AttrGetTPThresholdIds, reply *[]string) error { +// GetTPThresholdIDs queries Threshold identities on specific tariff plan. +func (api *APIerSv1) GetTPThresholdIDs(attrs *AttrGetTPThresholdIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPThresholds, - utils.TPDistinctIds{"id"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPThresholds, + utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Threshold on Tariff plan -func (self *APIerSv1) RemoveTPThreshold(attrs *utils.TPTntID, reply *string) error { +// RemoveTPThreshold removes specific Threshold on Tariff plan +func (api *APIerSv1) RemoveTPThreshold(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPThresholds, attrs.TPid, + if err := api.StorDb.RemTpData(utils.TBLTPThresholds, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/apier/v1/tpthresholds_it_test.go b/apier/v1/tpthresholds_it_test.go index 822295d39..b490bd72b 100644 --- a/apier/v1/tpthresholds_it_test.go +++ b/apier/v1/tpthresholds_it_test.go @@ -164,7 +164,7 @@ func testTPThreholdGetTPThreholdAfterSet(t *testing.T) { func testTPThreholdGetTPThreholdIds(t *testing.T) { var result []string - expectedTPID := []string{"Threshold"} + expectedTPID := []string{"cgrates.org:Threshold"} if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThresholdIDs, &AttrGetTPThresholdIds{TPid: tpThreshold.TPid}, &result); err != nil { t.Fatal(err) diff --git a/apier/v1/tptimings.go b/apier/v1/tptimings.go index cf30f375d..f4b787e03 100644 --- a/apier/v1/tptimings.go +++ b/apier/v1/tptimings.go @@ -22,12 +22,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new timing within a tariff plan -func (self *APIerSv1) SetTPTiming(attrs utils.ApierTPTiming, reply *string) error { +// SetTPTiming creates a new timing within a tariff plan +func (api *APIerSv1) SetTPTiming(attrs utils.ApierTPTiming, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID", "Years", "Months", "MonthDays", "WeekDays", "Time"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPTimings([]*utils.ApierTPTiming{&attrs}); err != nil { + if err := api.StorDb.SetTPTimings([]*utils.ApierTPTiming{&attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -39,19 +39,19 @@ type AttrGetTPTiming struct { ID string // Timing id } -// Queries specific Timing on Tariff plan -func (self *APIerSv1) GetTPTiming(attrs AttrGetTPTiming, reply *utils.ApierTPTiming) error { +// GetTPTiming queries specific Timing on Tariff plan +func (api *APIerSv1) GetTPTiming(attrs AttrGetTPTiming, reply *utils.ApierTPTiming) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if tms, err := self.StorDb.GetTPTimings(attrs.TPid, attrs.ID); err != nil { + tms, err := api.StorDb.GetTPTimings(attrs.TPid, attrs.ID) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = *tms[0] } + *reply = *tms[0] return nil } @@ -60,32 +60,31 @@ type AttrGetTPTimingIds struct { utils.PaginatorWithSearch } -// Queries timing identities on specific tariff plan. -func (self *APIerSv1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error { +// GetTPTimingIds queries timing identities on specific tariff plan. +func (api *APIerSv1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPTimings, - utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch); err != nil { + ids, err := api.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPTimings, + utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch) + if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } return err - } else { - *reply = ids } + *reply = ids return nil } -// Removes specific Timing on Tariff plan -func (self *APIerSv1) RemoveTPTiming(attrs AttrGetTPTiming, reply *string) error { +// RemoveTPTiming removes specific Timing on Tariff plan +func (api *APIerSv1) RemoveTPTiming(attrs AttrGetTPTiming, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPTimings, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := api.StorDb.RemTpData(utils.TBLTPTimings, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) - } else { - *reply = utils.OK } + *reply = utils.OK return nil } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 4ec7299a6..e17c2947f 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -217,11 +217,11 @@ func (self *SQLStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti if err != nil { return nil, err } - finalId := vals[0] + finalID := vals[0] if len(vals) > 1 { - finalId = strings.Join(vals, utils.CONCATENATED_KEY_SEP) + finalID = strings.Join(vals, utils.CONCATENATED_KEY_SEP) } - ids = append(ids, finalId) + ids = append(ids, finalID) } if i == 0 { return nil, nil diff --git a/migrator/tp_chargers.go b/migrator/tp_chargers.go index 1b073b23d..6332d5c3d 100755 --- a/migrator/tp_chargers.go +++ b/migrator/tp_chargers.go @@ -42,20 +42,19 @@ func (m *Migrator) migrateCurrentTPChargers() (err error) { if err != nil { return err } - if chargers != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPChargers(chargers); err != nil { - return err - } - for _, charger := range chargers { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPChargers, charger.TPid, - map[string]string{"id": charger.ID}); err != nil { - return err - } - } - m.stats[utils.TpChargers] += 1 + if chargers == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPChargers(chargers); err != nil { + return err + } + for _, charger := range chargers { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPChargers, charger.TPid, + map[string]string{"id": charger.ID}); err != nil { + return err } } + m.stats[utils.TpChargers] ++ } } return diff --git a/migrator/tp_dispatchers.go b/migrator/tp_dispatchers.go index 2beb6da90..774ad8653 100644 --- a/migrator/tp_dispatchers.go +++ b/migrator/tp_dispatchers.go @@ -42,20 +42,19 @@ func (m *Migrator) migrateCurrentTPDispatchers() (err error) { if err != nil { return err } - if dispatchers != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPDispatcherProfiles(dispatchers); err != nil { - return err - } - for _, dispatcher := range dispatchers { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPDispatchers, dispatcher.TPid, - map[string]string{"id": dispatcher.ID}); err != nil { - return err - } - } - m.stats[utils.TpDispatchers] += 1 + if dispatchers == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPDispatcherProfiles(dispatchers); err != nil { + return err + } + for _, dispatcher := range dispatchers { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPDispatchers, dispatcher.TPid, + map[string]string{"id": dispatcher.ID}); err != nil { + return err } } + m.stats[utils.TpDispatchers]++ } } return diff --git a/migrator/tp_filters.go b/migrator/tp_filters.go index 437ffcc03..ba17232e9 100644 --- a/migrator/tp_filters.go +++ b/migrator/tp_filters.go @@ -41,20 +41,19 @@ func (m *Migrator) migrateCurrentTPfilters() (err error) { if err != nil { return err } - if fltrs != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPFilters(fltrs); err != nil { - return err - } - for _, fltr := range fltrs { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPFilters, - fltr.TPid, map[string]string{"tenant": fltr.Tenant, "id": fltr.ID}); err != nil { - return err - } - } - m.stats[utils.TpFilters] += 1 + if fltrs == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPFilters(fltrs); err != nil { + return err + } + for _, fltr := range fltrs { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPFilters, + fltr.TPid, map[string]string{"tenant": fltr.Tenant, "id": fltr.ID}); err != nil { + return err } } + m.stats[utils.TpFilters]++ } } return diff --git a/migrator/tp_resources.go b/migrator/tp_resources.go index 8c80b9d92..332a43fed 100644 --- a/migrator/tp_resources.go +++ b/migrator/tp_resources.go @@ -43,20 +43,19 @@ func (m *Migrator) migrateCurrentTPresources() (err error) { if err != nil { return err } - if resources != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPResources(resources); err != nil { - return err - } - for _, resource := range resources { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPResources, resource.TPid, - map[string]string{"id": resource.ID}); err != nil { - return err - } - } - m.stats[utils.TpResources] += 1 + if resources == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPResources(resources); err != nil { + return err + } + for _, resource := range resources { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPResources, resource.TPid, + map[string]string{"id": resource.ID}); err != nil { + return err } } + m.stats[utils.TpResources]++ } } return diff --git a/migrator/tp_stats.go b/migrator/tp_stats.go index db0f561f4..04257248c 100644 --- a/migrator/tp_stats.go +++ b/migrator/tp_stats.go @@ -38,25 +38,23 @@ func (m *Migrator) migrateCurrentTPstats() (err error) { return err } for _, id := range ids { - stats, err := m.storDBIn.StorDB().GetTPStats(tpid, "", id) if err != nil { return err } - if stats != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPStats(stats); err != nil { - return err - } - for _, stat := range stats { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPStats, stat.TPid, - map[string]string{"id": stat.ID}); err != nil { - return err - } - } - m.stats[utils.TpStats] += 1 + if stats == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPStats(stats); err != nil { + return err + } + for _, stat := range stats { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPStats, stat.TPid, + map[string]string{"id": stat.ID}); err != nil { + return err } } + m.stats[utils.TpStats]++ } } return diff --git a/migrator/tp_suppliers.go b/migrator/tp_suppliers.go index daddc24b7..f1d5ac0a7 100644 --- a/migrator/tp_suppliers.go +++ b/migrator/tp_suppliers.go @@ -38,26 +38,24 @@ func (m *Migrator) migrateCurrentTPSuppliers() (err error) { return err } for _, id := range ids { - suppliers, err := m.storDBIn.StorDB().GetTPSuppliers(tpid, "", id) if err != nil { return err } - if suppliers != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPSuppliers(suppliers); err != nil { - return err - } - for _, supplier := range suppliers { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPSuppliers, supplier.TPid, - map[string]string{"tenant": supplier.Tenant, "id": supplier.ID}); err != nil { - return err - } - } - - m.stats[utils.TpSuppliers] += 1 + if suppliers == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPSuppliers(suppliers); err != nil { + return err + } + for _, supplier := range suppliers { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPSuppliers, supplier.TPid, + map[string]string{"tenant": supplier.Tenant, "id": supplier.ID}); err != nil { + return err } } + + m.stats[utils.TpSuppliers]++ } } return diff --git a/migrator/tp_thresholds.go b/migrator/tp_thresholds.go index b6c9d7330..29f8af35e 100644 --- a/migrator/tp_thresholds.go +++ b/migrator/tp_thresholds.go @@ -38,25 +38,23 @@ func (m *Migrator) migrateCurrentTPthresholds() (err error) { return err } for _, id := range ids { - thresholds, err := m.storDBIn.StorDB().GetTPThresholds(tpid, "", id) if err != nil { return err } - if thresholds != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPThresholds(thresholds); err != nil { - return err - } - for _, threshold := range thresholds { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPThresholds, threshold.TPid, - map[string]string{"tenant": threshold.Tenant, "id": threshold.ID}); err != nil { - return err - } - } - m.stats[utils.TpThresholds] += 1 + if thresholds == nil || m.dryRun { + continue + } + if err := m.storDBOut.StorDB().SetTPThresholds(thresholds); err != nil { + return err + } + for _, threshold := range thresholds { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPThresholds, threshold.TPid, + map[string]string{"tenant": threshold.Tenant, "id": threshold.ID}); err != nil { + return err } } + m.stats[utils.TpThresholds]++ } } return