mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Add AliasProfile in Apier
This commit is contained in:
committed by
Dan Christian Bogos
parent
dbf77721b2
commit
de6cda4a9b
95
apier/v1/aliasprofile.go
Normal file
95
apier/v1/aliasprofile.go
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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 (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type ApierAliasProfile struct {
|
||||
Tenant string
|
||||
ID string
|
||||
FilterIDs []string
|
||||
ActivationInterval *utils.ActivationInterval // Activation interval
|
||||
Aliases []*ApierAliasEntry
|
||||
Weight float64
|
||||
}
|
||||
|
||||
type ApierAliasEntry struct {
|
||||
FieldName string
|
||||
Initial string
|
||||
Alias string
|
||||
}
|
||||
|
||||
// GetAliasProfile returns an Alias Profile
|
||||
func (apierV1 *ApierV1) GetAliasProfile(arg utils.TenantID, reply *engine.AliasProfile) error {
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if alsPrf, err := apierV1.DataManager.GetAliasProfile(arg.Tenant, arg.ID, false, utils.NonTransactional); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
*reply = *alsPrf
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//SetAliasProfile add a new Alias Profile
|
||||
func (apierV1 *ApierV1) SetAliasProfile(alsPrf *ApierAliasProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(alsPrf, []string{"Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
alsPrfEngine := &engine.AliasProfile{
|
||||
Tenant: alsPrf.Tenant,
|
||||
ID: alsPrf.ID,
|
||||
Weight: alsPrf.Weight,
|
||||
FilterIDs: alsPrf.FilterIDs,
|
||||
ActivationInterval: alsPrf.ActivationInterval,
|
||||
}
|
||||
alsMap := make(map[string]map[string]string)
|
||||
for _, als := range alsPrf.Aliases {
|
||||
alsMap[als.FieldName] = make(map[string]string)
|
||||
alsMap[als.FieldName][als.Initial] = als.Alias
|
||||
}
|
||||
alsPrfEngine.Aliases = alsMap
|
||||
if err := apierV1.DataManager.SetAliasProfile(alsPrfEngine); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
//RemAliasProfile remove a specific Alias Profile
|
||||
func (apierV1 *ApierV1) RemAliasProfile(arg utils.TenantID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierV1.DataManager.RemoveAliasProfile(arg.Tenant, arg.ID, utils.NonTransactional); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user