mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
Added default tenant to /apier/v1/
This commit is contained in:
committed by
Dan Christian Bogos
parent
e96196b2f7
commit
489b72182d
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// SetTPDestinationRate creates a new DestinationRate profile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPDestinationRate(attrs *utils.TPDestinationRate, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "DestinationRates"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.DestinationRates}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPDestinationRates([]*utils.TPDestinationRate{attrs}); err != nil {
|
||||
@@ -44,7 +44,7 @@ type AttrGetTPDestinationRate struct {
|
||||
|
||||
// GetTPDestinationRate queries specific DestinationRate profile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
drs, err := apierSv1.StorDb.GetTPDestinationRates(attrs.TPid, attrs.ID, &attrs.Paginator)
|
||||
@@ -65,11 +65,11 @@ type AttrTPDestinationRateIds struct {
|
||||
|
||||
// GetTPDestinationRateIds queries DestinationRate identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPDestinationRateIds(attrs *AttrGetTPRateIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinationRates,
|
||||
utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -82,10 +82,10 @@ func (apierSv1 *APIerSv1) GetTPDestinationRateIds(attrs *AttrGetTPRateIds, reply
|
||||
|
||||
// RemoveTPDestinationRate removes specific DestinationRate on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinationRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinationRates, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
// SetTPDestination creates a new destination within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPDestination(attrs *utils.TPDestination, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "Prefixes"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.Prefixes}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPDestinations([]*utils.TPDestination{attrs}); err != nil {
|
||||
@@ -41,7 +41,7 @@ type AttrGetTPDestination struct {
|
||||
|
||||
// GetTPDestination queries a specific destination
|
||||
func (apierSv1 *APIerSv1) GetTPDestination(attrs *AttrGetTPDestination, reply *utils.TPDestination) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tpDsts, err := apierSv1.StorDb.GetTPDestinations(attrs.TPid, attrs.ID)
|
||||
@@ -64,11 +64,11 @@ type AttrGetTPDestinationIds struct {
|
||||
|
||||
// GetTPDestinationIDs queries destination identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPDestinationIDs(attrs *AttrGetTPDestinationIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinations,
|
||||
utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -81,10 +81,10 @@ func (apierSv1 *APIerSv1) GetTPDestinationIDs(attrs *AttrGetTPDestinationIds, re
|
||||
|
||||
// RemoveTPDestination removes specific Destination on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPDestination(attrs *AttrGetTPDestination, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -24,9 +24,13 @@ import (
|
||||
|
||||
// SetTPDispatcherProfile creates a new DispatcherProfile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPDispatcherProfiles([]*utils.TPDispatcherProfile{attr}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -36,9 +40,13 @@ func (apierSv1 *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile
|
||||
|
||||
// GetTPDispatcherProfile queries specific DispatcherProfile on Tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
rls, err := apierSv1.StorDb.GetTPDispatcherProfiles(attr.TPid, attr.Tenant, attr.ID)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -57,10 +65,10 @@ type AttrGetTPDispatcherIds struct {
|
||||
|
||||
// GetTPDispatcherProfileIDs queries dispatcher identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatchers, utils.TPDistinctIds{"tenant", "id"},
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatchers, utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg},
|
||||
nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -74,11 +82,15 @@ func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherId
|
||||
|
||||
// RemoveTPDispatcherProfile removes specific DispatcherProfile on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDispatchers, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
@@ -87,9 +99,13 @@ func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply
|
||||
|
||||
// SetTPDispatcherHost creates a new DispatcherHost within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPDispatcherHosts([]*utils.TPDispatcherHost{attr}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -99,9 +115,13 @@ func (apierSv1 *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, repl
|
||||
|
||||
// GetTPDispatcherHost queries specific DispatcherHosts on Tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.TPDispatcherHost) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
rls, err := apierSv1.StorDb.GetTPDispatcherHosts(attr.TPid, attr.Tenant, attr.ID)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -115,10 +135,10 @@ func (apierSv1 *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.
|
||||
|
||||
// GetTPDispatcherHostIDs queries dispatcher host identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatcherHosts, utils.TPDistinctIds{"tenant", "id"},
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatcherHosts, utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg},
|
||||
nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -132,11 +152,15 @@ func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds,
|
||||
|
||||
// RemoveTPDispatcherHost removes specific DispatcherHost on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPDispatcherHost(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPDispatcherHosts, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -24,9 +24,13 @@ import (
|
||||
|
||||
// SetTPFilterProfile creates a new FilterProfile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPFilters([]*utils.TPFilterProfile{attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -36,9 +40,13 @@ func (apierSv1 *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply
|
||||
|
||||
// GetTPFilterProfile queries specific FilterProfile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPFilterProfile(attr *utils.TPTntID, reply *utils.TPFilterProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
filter, err := apierSv1.StorDb.GetTPFilters(attr.TPid, attr.Tenant, attr.ID)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -57,10 +65,10 @@ type AttrGetTPFilterProfileIds struct {
|
||||
|
||||
// GetTPFilterProfileIds queries FilterProfile identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPFilters, utils.TPDistinctIds{"tenant", "id"},
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPFilters, utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg},
|
||||
nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -74,11 +82,15 @@ func (apierSv1 *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds
|
||||
|
||||
// RemoveTPFilterProfile removes specific FilterProfile on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPFilterProfile(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPFilters, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -24,9 +24,13 @@ import (
|
||||
|
||||
// SetTPRateProfile creates a new TPRateProfile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPRateProfile(attrs *utils.TPRateProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPRateProfiles([]*utils.TPRateProfile{attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -36,9 +40,13 @@ func (apierSv1 *APIerSv1) SetTPRateProfile(attrs *utils.TPRateProfile, reply *st
|
||||
|
||||
// GetTPRateProfile queries specific TPRateProfile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPRateProfile(attr *utils.TPTntID, reply *utils.TPRateProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
filter, err := apierSv1.StorDb.GetTPRateProfiles(attr.TPid, attr.Tenant, attr.ID)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -57,10 +65,10 @@ type AttrGetTPRateProfileIds struct {
|
||||
|
||||
// GetTPRateProfileIds queries TPRateProfiles identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPRateProfileIds(attrs *AttrGetTPRateProfileIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, utils.TPDistinctIds{"tenant", "id"},
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg},
|
||||
nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -74,11 +82,15 @@ func (apierSv1 *APIerSv1) GetTPRateProfileIds(attrs *AttrGetTPRateProfileIds, re
|
||||
|
||||
// RemoveTPRateProfile removes specific TPRateProfile on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPRateProfile(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRateProfiles, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
247
apier/v1/tprateprofiles_it_test.go
Normal file
247
apier/v1/tprateprofiles_it_test.go
Normal file
@@ -0,0 +1,247 @@
|
||||
// +build offline
|
||||
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
tpRatePrfCfgPath string
|
||||
tpRatePrfCfg *config.CGRConfig
|
||||
tpRatePrfRPC *rpc.Client
|
||||
tpRatePrfDataDir = "/usr/share/cgrates"
|
||||
tpRatePrf *utils.TPRateProfile
|
||||
tpRatePrfDelay int
|
||||
tpRatePrfConfigDIR string //run tests for specific configuration
|
||||
)
|
||||
|
||||
var sTestsTPRatePrf = []func(t *testing.T){
|
||||
testTPRatePrfInitCfg,
|
||||
testTPRatePrfResetStorDb,
|
||||
testTPRatePrfStartEngine,
|
||||
testTPRatePrfRPCConn,
|
||||
testTPRatePrfGetTPRatePrfBeforeSet,
|
||||
testTPRatePrfSetTPRatePrf,
|
||||
testTPRatePrfGetTPRatePrfAfterSet,
|
||||
testTPRatePrfGetTPRatePrfIDs,
|
||||
testTPRatePrfUpdateTPRatePrf,
|
||||
testTPRatePrfGetTPRatePrfAfterUpdate,
|
||||
testTPRatePrfRemTPRatePrf,
|
||||
testTPRatePrfGetTPRatePrfAfterRemove,
|
||||
testTPRatePrfKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestTPRatePrfIT(t *testing.T) {
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
tpRatePrfConfigDIR = "tutinternal"
|
||||
case utils.MetaMySQL:
|
||||
tpRatePrfConfigDIR = "tutmysql"
|
||||
case utils.MetaMongo:
|
||||
tpRatePrfConfigDIR = "tutmongo"
|
||||
case utils.MetaPostgres:
|
||||
t.SkipNow()
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, stest := range sTestsTPRatePrf {
|
||||
t.Run(tpRatePrfConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfInitCfg(t *testing.T) {
|
||||
var err error
|
||||
tpRatePrfCfgPath = path.Join(tpRatePrfDataDir, "conf", "samples", tpRatePrfConfigDIR)
|
||||
tpRatePrfCfg, err = config.NewCGRConfigFromPath(tpRatePrfCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpRatePrfDelay = 1000
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testTPRatePrfResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(tpRatePrfCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testTPRatePrfStartEngine(t *testing.T) {
|
||||
if _, err := engine.StopStartEngine(tpRatePrfCfgPath, tpRatePrfDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testTPRatePrfRPCConn(t *testing.T) {
|
||||
var err error
|
||||
tpRatePrfRPC, err = jsonrpc.Dial(utils.TCP, tpRatePrfCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfGetTPRatePrfBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPRateProfile
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfSetTPRatePrf(t *testing.T) {
|
||||
tpRatePrf = &utils.TPRateProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RT_SPECIAL_1002",
|
||||
Weight: 10,
|
||||
RoundingDecimals: 4,
|
||||
RoundingMethod: "*up",
|
||||
Rates: map[string]*utils.TPRate{
|
||||
"RT_ALWAYS": {
|
||||
ID: "RT_ALWAYS",
|
||||
FilterIDs: []string{"* * * * *"},
|
||||
Weight: 0,
|
||||
Blocker: false,
|
||||
IntervalRates: []*utils.TPIntervalRate{
|
||||
{
|
||||
IntervalStart: "0s",
|
||||
RecurrentFee: 0.01,
|
||||
Unit: "1m",
|
||||
Increment: "1s",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
sort.Strings(tpRatePrf.FilterIDs)
|
||||
var result string
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1SetTPRateProfile, tpRatePrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfGetTPRatePrfAfterSet(t *testing.T) {
|
||||
var reply *utils.TPRateProfile
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Strings(reply.FilterIDs)
|
||||
if !reflect.DeepEqual(tpRatePrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpRatePrf), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfGetTPRatePrfIDs(t *testing.T) {
|
||||
var result []string
|
||||
expectedTPID := []string{"cgrates.org:RT_SPECIAL_1002"}
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfileIds,
|
||||
&AttrGetTPRateProfileIds{TPid: "TP1"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedTPID, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfUpdateTPRatePrf(t *testing.T) {
|
||||
tpRatePrf.Rates = map[string]*utils.TPRate{
|
||||
"RT_ALWAYS": {
|
||||
ID: "RT_ALWAYS",
|
||||
FilterIDs: []string{"* * * * *"},
|
||||
Weight: 0,
|
||||
Blocker: false,
|
||||
IntervalRates: []*utils.TPIntervalRate{
|
||||
{
|
||||
IntervalStart: "0s",
|
||||
RecurrentFee: 0.01,
|
||||
Unit: "1m",
|
||||
Increment: "1s",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1SetTPRateProfile, tpRatePrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfGetTPRatePrfAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPRateProfile
|
||||
revTPRatePrf := &utils.TPRateProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RT_SPECIAL_1002",
|
||||
Weight: 10,
|
||||
}
|
||||
sort.Strings(revTPRatePrf.FilterIDs)
|
||||
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(tpRatePrf, reply) && !reflect.DeepEqual(revTPRatePrf, reply) {
|
||||
t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpRatePrf), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfRemTPRatePrf(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1RemoveTPRateProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"},
|
||||
&resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfGetTPRatePrfAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPActionProfile
|
||||
if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"},
|
||||
&reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTPRatePrfKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(tpRatePrfDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// SetTPRate creates a new rate within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPRate(attrs *utils.TPRateRALs, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "RateSlots"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RateSlots}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPRates([]*utils.TPRateRALs{attrs}); err != nil {
|
||||
@@ -43,7 +43,7 @@ type AttrGetTPRate struct {
|
||||
|
||||
// GetTPRate queries specific Rate on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPRate(attrs *AttrGetTPRate, reply *utils.TPRateRALs) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
rs, err := apierSv1.StorDb.GetTPRates(attrs.TPid, attrs.ID)
|
||||
@@ -64,11 +64,11 @@ type AttrGetTPRateIds struct {
|
||||
|
||||
// GetTPRateIds queries rate identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPRateIds(attrs *AttrGetTPRateIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRates,
|
||||
utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -81,10 +81,10 @@ func (apierSv1 *APIerSv1) GetTPRateIds(attrs *AttrGetTPRateIds, reply *[]string)
|
||||
|
||||
// RemoveTPRate removes specific Rate on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPRate(attrs *AttrGetTPRate, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRates, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRates, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// SetTPRatingPlan creates a new DestinationRateTiming profile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPRatingPlan(attrs *utils.TPRatingPlan, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "RatingPlanBindings"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RatingPlanBindings}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPRatingPlans([]*utils.TPRatingPlan{attrs}); err != nil {
|
||||
@@ -44,7 +44,7 @@ type AttrGetTPRatingPlan struct {
|
||||
|
||||
// GetTPRatingPlan queries specific RatingPlan profile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
rps, err := apierSv1.StorDb.GetTPRatingPlans(attrs.TPid, attrs.ID, &attrs.Paginator)
|
||||
@@ -65,11 +65,11 @@ type AttrGetTPRatingPlanIds struct {
|
||||
|
||||
// GetTPRatingPlanIds queries RatingPlan identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPRatingPlanIds(attrs *AttrGetTPRatingPlanIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingPlans,
|
||||
utils.TPDistinctIds{"tag"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -82,10 +82,10 @@ func (apierSv1 *APIerSv1) GetTPRatingPlanIds(attrs *AttrGetTPRatingPlanIds, repl
|
||||
|
||||
// RemoveTPRatingPlan removes specific RatingPlan on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRatingPlans, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPRatingPlans, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -27,9 +27,13 @@ import (
|
||||
// SetTPRatingProfile creates a new RatingProfile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPRatingProfile(attrs *utils.TPRatingProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs,
|
||||
[]string{"TPid", "LoadId", "Tenant", "Category", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
|
||||
[]string{utils.TPid, utils.LoadId, utils.Category, utils.Subject, utils.RatingPlanActivations}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPRatingProfiles([]*utils.TPRatingProfile{attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -39,13 +43,17 @@ func (apierSv1 *APIerSv1) SetTPRatingProfile(attrs *utils.TPRatingProfile, reply
|
||||
|
||||
// GetTPRatingProfilesByLoadID queries specific RatingProfile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(attrs *utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error {
|
||||
mndtryFlds := []string{"TPid", "LoadId"}
|
||||
mndtryFlds := []string{utils.TPid, utils.LoadId}
|
||||
if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory
|
||||
mndtryFlds = append(mndtryFlds, "Tenant", "Category", "Subject")
|
||||
mndtryFlds = append(mndtryFlds, utils.Category, utils.Subject)
|
||||
}
|
||||
if missing := utils.MissingStructFields(attrs, mndtryFlds); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
rps, err := apierSv1.StorDb.GetTPRatingProfiles(attrs)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -59,14 +67,18 @@ func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(attrs *utils.TPRatingProfi
|
||||
|
||||
// GetTPRatingProfileLoadIds queries RatingProfile identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPRatingProfileLoadIds(attrs *utils.AttrTPRatingProfileIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingProfiles,
|
||||
utils.TPDistinctIds{"loadid"}, map[string]string{
|
||||
"tenant": attrs.Tenant,
|
||||
"category": attrs.Category,
|
||||
"subject": attrs.Subject,
|
||||
utils.TPDistinctIds{utils.Loadid}, map[string]string{
|
||||
utils.TenantCfg: attrs.Tenant,
|
||||
utils.CategoryLowerCase: attrs.Category,
|
||||
utils.SubjectLowerCase: attrs.Subject,
|
||||
}, new(utils.PaginatorWithSearch))
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -86,13 +98,17 @@ type AttrGetTPRatingProfile struct {
|
||||
|
||||
// GetTPRatingProfile queries specific RatingProfile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "RatingProfileID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tmpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
|
||||
if err := tmpRpf.SetRatingProfileID(attrs.RatingProfileID); err != nil {
|
||||
return err
|
||||
}
|
||||
tnt := tmpRpf.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
rpfs, err := apierSv1.StorDb.GetTPRatingProfiles(tmpRpf)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -112,11 +128,11 @@ type AttrGetTPRatingProfileIds struct {
|
||||
|
||||
// GetTPRatingProfileIds queries RatingProfiles identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPRatingProfileIds(attrs *AttrGetTPRatingProfileIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRatingProfiles,
|
||||
utils.TPDistinctIds{"loadid", "tenant", "category", "subject"},
|
||||
utils.TPDistinctIds{utils.Loadid, utils.TenantCfg, utils.CategoryLowerCase, utils.SubjectLowerCase},
|
||||
nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -130,19 +146,23 @@ func (apierSv1 *APIerSv1) GetTPRatingProfileIds(attrs *AttrGetTPRatingProfileIds
|
||||
|
||||
// RemoveTPRatingProfile removes specific RatingProfiles on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "RatingProfileID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tmpRpf := new(utils.TPRatingProfile)
|
||||
if err = tmpRpf.SetRatingProfileID(attrs.RatingProfileID); err != nil {
|
||||
return
|
||||
}
|
||||
tnt := tmpRpf.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
err = apierSv1.StorDb.RemTpData(utils.TBLTPRatingProfiles,
|
||||
attrs.TPid, map[string]string{
|
||||
"loadid": tmpRpf.LoadId,
|
||||
"tenant": tmpRpf.Tenant,
|
||||
"category": tmpRpf.Category,
|
||||
"subject": tmpRpf.Subject,
|
||||
utils.Loadid: tmpRpf.LoadId,
|
||||
utils.TenantCfg: tmpRpf.Tenant,
|
||||
utils.CategoryLowerCase: tmpRpf.Category,
|
||||
utils.SubjectLowerCase: tmpRpf.Subject,
|
||||
})
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -24,9 +24,13 @@ import (
|
||||
|
||||
// SetTPResource creates a new resource within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID", "Limit"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID, utils.Limit}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPResources([]*utils.TPResourceProfile{attr}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -36,9 +40,13 @@ func (apierSv1 *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *st
|
||||
|
||||
// GetTPResource queries specific Resource on Tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPResource(attr *utils.TPTntID, reply *utils.TPResourceProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
rls, err := apierSv1.StorDb.GetTPResources(attr.TPid, attr.Tenant, attr.ID)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -57,11 +65,11 @@ type AttrGetTPResourceIds struct {
|
||||
|
||||
// GetTPResourceIDs queries Resource identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResources,
|
||||
utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -74,10 +82,14 @@ func (apierSv1 *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[
|
||||
|
||||
// RemoveTPResource removes specific Resource on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPResource(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -920,6 +920,13 @@ const (
|
||||
ActionPlan = "ActionPlan"
|
||||
ActionsId = "ActionsId"
|
||||
TimingId = "TimingId"
|
||||
Prefixes = "Prefixes"
|
||||
RateSlots = "RateSlots"
|
||||
RatingPlanBindings = "RatingPlanBindings"
|
||||
RatingPlanActivations = "RatingPlanActivations"
|
||||
CategoryLowerCase = "category"
|
||||
SubjectLowerCase = "subject"
|
||||
RatingProfileID = "RatingProfileID"
|
||||
)
|
||||
|
||||
// Migrator Action
|
||||
@@ -1431,6 +1438,10 @@ const (
|
||||
APIerSv1SetTPActionProfile = "APIerSv1.SetTPActionProfile"
|
||||
APIerSv1GetTPActionProfileIDs = "APIerSv1.GetTPActionProfileIDs"
|
||||
APIerSv1RemoveTPActionProfile = "APIerSv1.RemoveTPActionProfile"
|
||||
APIerSv1GetTPRateProfile = "APIerSv1.GetTPRateProfile"
|
||||
APIerSv1SetTPRateProfile = "APIerSv1.SetTPRateProfile"
|
||||
APIerSv1GetTPRateProfileIds = "APIerSv1.GetTPRateProfileIds"
|
||||
APIerSv1RemoveTPRateProfile = "APIerSv1.RemoveTPRateProfile"
|
||||
)
|
||||
|
||||
// APIerSv1 TP APIs
|
||||
|
||||
Reference in New Issue
Block a user