Files
cgrates/apier/v1/aliasprofile.go

69 lines
2.4 KiB
Go

/*
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"
)
// GetAliasProfile returns an Alias Profile
func (apierV1 *ApierV1) GetAliasProfile(arg utils.TenantID, reply *engine.ExternalAliasProfile) 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, true, utils.NonTransactional); err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
} else {
*reply = *engine.NewExternalAliasProfileFromAliasProfile(alsPrf)
}
return nil
}
//SetAliasProfile add a new Alias Profile
func (apierV1 *ApierV1) SetAliasProfile(extAls *engine.ExternalAliasProfile, reply *string) error {
if missing := utils.MissingStructFields(extAls, []string{"Tenant", "ID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
alsPrf := extAls.AsAliasProfile()
if err := apierV1.DataManager.SetAliasProfile(alsPrf); 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
}