mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
Added missing tenant case for /apier/v1/tp....go files
This commit is contained in:
committed by
Dan Christian Bogos
parent
4dcba6fcdd
commit
01c92e7da4
@@ -26,9 +26,13 @@ import (
|
||||
// SetTPAccountActions creates a new AccountActions profile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPAccountActions(attrs *utils.TPAccountActions, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs,
|
||||
[]string{"TPid", "LoadId", "Tenant", "Account", "ActionPlanId"}); len(missing) != 0 {
|
||||
[]string{utils.TPid, utils.LoadId, utils.Account, utils.ActionPlanId}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.StorDb.SetTPAccountActions([]*utils.TPAccountActions{attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -43,13 +47,17 @@ type AttrGetTPAccountActionsByLoadId struct {
|
||||
|
||||
// GetTPAccountActionsByLoadId queries specific AccountActions profile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPAccountActionsByLoadId(attrs *utils.TPAccountActions, reply *[]*utils.TPAccountActions) error {
|
||||
mndtryFlds := []string{"TPid", "LoadId"}
|
||||
mndtryFlds := []string{utils.TPid, utils.LoadId}
|
||||
if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory
|
||||
mndtryFlds = append(mndtryFlds, "Tenant", "Account")
|
||||
mndtryFlds = append(mndtryFlds, utils.Account)
|
||||
}
|
||||
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
|
||||
}
|
||||
aas, err := apierSv1.StorDb.GetTPAccountActions(attrs)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
@@ -68,7 +76,7 @@ type AttrGetTPAccountActions struct {
|
||||
|
||||
// GetTPAccountActions queries specific DerivedCharge on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPAccountActions(attrs *AttrGetTPAccountActions, reply *utils.TPAccountActions) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.AccountActionsId}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
filter := &utils.TPAccountActions{TPid: attrs.TPid}
|
||||
@@ -93,11 +101,11 @@ type AttrGetTPAccountActionIds struct {
|
||||
|
||||
// GetTPAccountActionLoadIds queries AccountActions identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(attrs *AttrGetTPAccountActionIds, 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.TBLTPAccountActions,
|
||||
utils.TPDistinctIds{"loadid"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.Loadid}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -110,11 +118,11 @@ func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(attrs *AttrGetTPAccountActio
|
||||
|
||||
// GetTPAccountActionIds queries DerivedCharges identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPAccountActionIds(attrs *AttrGetTPAccountActionIds, 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.TBLTPAccountActions,
|
||||
utils.TPDistinctIds{"loadid", "tenant", "account"}, nil, &attrs.PaginatorWithSearch)
|
||||
utils.TPDistinctIds{utils.Loadid, utils.TenantCfg, utils.AccountLowerCase}, nil, &attrs.PaginatorWithSearch)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -127,15 +135,16 @@ func (apierSv1 *APIerSv1) GetTPAccountActionIds(attrs *AttrGetTPAccountActionIds
|
||||
|
||||
// RemoveTPAccountActions removes specific AccountActions on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPAccountActions(attrs *AttrGetTPAccountActions, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "LoadId", "Tenant", "Account"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.LoadId, utils.Account}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
aa := engine.AccountActionMdl{Tpid: attrs.TPid}
|
||||
if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apierSv1.StorDb.RemTpData(utils.TBLTPAccountActions, aa.Tpid,
|
||||
map[string]string{"loadid": aa.Loadid, "tenant": aa.Tenant, "account": aa.Account}); err != nil {
|
||||
map[string]string{utils.Loadid: aa.Loadid, utils.TenantCfg: aa.Tenant, utils.AccountLowerCase: aa.Account}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -26,11 +26,11 @@ import (
|
||||
|
||||
// SetTPActionPlan creates a new ActionTimings profile within a tariff plan
|
||||
func (apierSv1 *APIerSv1) SetTPActionPlan(attrs *utils.TPActionPlan, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "ActionPlan"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.ActionPlan}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
for _, at := range attrs.ActionPlan {
|
||||
requiredFields := []string{"ActionsId", "TimingId", "Weight"}
|
||||
requiredFields := []string{utils.ActionsId, utils.TimingId, utils.Weight}
|
||||
if missing := utils.MissingStructFields(at, requiredFields); len(missing) != 0 {
|
||||
return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), at.ActionsId, missing)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ type AttrGetTPActionPlan struct {
|
||||
|
||||
// GetTPActionPlan queries specific ActionPlan profile on tariff plan
|
||||
func (apierSv1 *APIerSv1) GetTPActionPlan(attrs *AttrGetTPActionPlan, reply *utils.TPActionPlan) 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...)
|
||||
}
|
||||
aps, err := apierSv1.StorDb.GetTPActionPlans(attrs.TPid, attrs.ID)
|
||||
@@ -70,11 +70,11 @@ type AttrGetTPActionPlanIds struct {
|
||||
|
||||
// GetTPActionPlanIds queries ActionPlan identities on specific tariff plan.
|
||||
func (apierSv1 *APIerSv1) GetTPActionPlanIds(attrs *AttrGetTPActionPlanIds, 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.TBLTPActionPlans,
|
||||
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)
|
||||
@@ -87,11 +87,11 @@ func (apierSv1 *APIerSv1) GetTPActionPlanIds(attrs *AttrGetTPActionPlanIds, repl
|
||||
|
||||
// RemoveTPActionPlan removes specific ActionPlan on Tariff plan
|
||||
func (apierSv1 *APIerSv1) RemoveTPActionPlan(attrs *AttrGetTPActionPlan, 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.TBLTPActionPlans,
|
||||
attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil {
|
||||
attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -909,6 +909,15 @@ const (
|
||||
ActionTTL = "ActionTTL"
|
||||
ActionOpts = "ActionOpts"
|
||||
ActionPath = "ActionPath"
|
||||
TPid = "TPid"
|
||||
LoadId = "LoadId"
|
||||
ActionPlanId = "ActionPlanId"
|
||||
AccountActionsId = "AccountActionsId"
|
||||
Loadid = "loadid"
|
||||
AccountLowerCase = "account"
|
||||
ActionPlan = "ActionPlan"
|
||||
ActionsId = "ActionsId"
|
||||
TimingId = "TimingId"
|
||||
)
|
||||
|
||||
// Migrator Action
|
||||
|
||||
Reference in New Issue
Block a user