Started renaming AccountPRofile into Account

This commit is contained in:
porosnicuadrian
2021-04-06 18:04:56 +03:00
committed by Dan Christian Bogos
parent 31414ca68b
commit 1f485d7cf9
28 changed files with 146 additions and 146 deletions

View File

@@ -26,7 +26,7 @@ import (
)
// AccountProfile represents one Account on a Tenant
type AccountProfile struct {
type Account struct {
Tenant string
ID string // Account identificator, unique within the tenant
FilterIDs []string
@@ -38,7 +38,7 @@ type AccountProfile struct {
}
// BalancesAltered detects altering of the Balances by comparing the Balance values with the ones from backup
func (ap *AccountProfile) BalancesAltered(abb AccountBalancesBackup) (altred bool) {
func (ap *Account) BalancesAltered(abb AccountBalancesBackup) (altred bool) {
if len(ap.Balances) != len(abb) {
return true
}
@@ -51,14 +51,14 @@ func (ap *AccountProfile) BalancesAltered(abb AccountBalancesBackup) (altred boo
return
}
func (ap *AccountProfile) RestoreFromBackup(abb AccountBalancesBackup) {
func (ap *Account) RestoreFromBackup(abb AccountBalancesBackup) {
for blncID, val := range abb {
ap.Balances[blncID].Units.Big = val
}
}
// AccountBalancesBackup returns a backup of all balance values
func (ap *AccountProfile) AccountBalancesBackup() (abb AccountBalancesBackup) {
func (ap *Account) AccountBalancesBackup() (abb AccountBalancesBackup) {
if ap.Balances != nil {
abb = make(AccountBalancesBackup)
for blncID, blnc := range ap.Balances {
@@ -185,13 +185,13 @@ func (uF *UnitFactor) Equals(nUf *UnitFactor) (eq bool) {
}
// TenantID returns the combined Tenant:ID
func (aP *AccountProfile) TenantID() string {
func (aP *Account) TenantID() string {
return ConcatenatedKey(aP.Tenant, aP.ID)
}
// Clone returns a clone of the Account
func (aP *AccountProfile) Clone() (acnt *AccountProfile) {
acnt = &AccountProfile{
func (aP *Account) Clone() (acnt *Account) {
acnt = &Account{
Tenant: aP.Tenant,
ID: aP.ID,
ActivationInterval: aP.ActivationInterval.Clone(),
@@ -285,33 +285,33 @@ func (bL *Balance) Clone() (blnc *Balance) {
}
// AccountProfileWithWeight attaches static weight to AccountProfile
type AccountProfileWithWeight struct {
*AccountProfile
type AccountWithWeight struct {
*Account
Weight float64
LockID string
}
// AccountProfilesWithWeight is a sortable list of AccountProfileWithWeight
type AccountProfilesWithWeight []*AccountProfileWithWeight
type AccountsWithWeight []*AccountWithWeight
// Sort is part of sort interface, sort based on Weight
func (aps AccountProfilesWithWeight) Sort() {
func (aps AccountsWithWeight) Sort() {
sort.Slice(aps, func(i, j int) bool { return aps[i].Weight > aps[j].Weight })
}
// AccountProfiles returns the list of AccountProfiles
func (apWws AccountProfilesWithWeight) AccountProfiles() (aps []*AccountProfile) {
func (apWws AccountsWithWeight) AccountProfiles() (aps []*Account) {
if apWws != nil {
aps = make([]*AccountProfile, len(apWws))
aps = make([]*Account, len(apWws))
for i, apWw := range apWws {
aps[i] = apWw.AccountProfile
aps[i] = apWw.Account
}
}
return
}
// LockIDs returns the list of LockIDs
func (apWws AccountProfilesWithWeight) LockIDs() (lkIDs []string) {
func (apWws AccountsWithWeight) LockIDs() (lkIDs []string) {
if apWws != nil {
lkIDs = make([]string, len(apWws))
for i, apWw := range apWws {
@@ -347,13 +347,13 @@ func (bWws BalancesWithWeight) Balances() (blncs []*Balance) {
}
// APIAccountProfileWithOpts is used in API calls
type APIAccountProfileWithOpts struct {
*APIAccountProfile
type APIAccountWithOpts struct {
*APIAccount
APIOpts map[string]interface{}
}
type AccountProfileWithAPIOpts struct {
*AccountProfile
type AccountWithAPIOpts struct {
*Account
APIOpts map[string]interface{}
}
@@ -364,7 +364,7 @@ type ArgsAccountsForEvent struct {
}
// APIAccountProfile represents one APIAccount on a Tenant
type APIAccountProfile struct {
type APIAccount struct {
Tenant string
ID string
FilterIDs []string
@@ -375,9 +375,9 @@ type APIAccountProfile struct {
ThresholdIDs []string
}
// AsAccountProfile convert APIAccountProfile struct to AccountProfile struct
func (ext *APIAccountProfile) AsAccountProfile() (profile *AccountProfile, err error) {
profile = &AccountProfile{
// AsAccount convert APIAccount struct to AccountProfile struct
func (ext *APIAccount) AsAccount() (profile *Account, err error) {
profile = &Account{
Tenant: ext.Tenant,
ID: ext.ID,
FilterIDs: ext.FilterIDs,

View File

@@ -68,7 +68,7 @@ func TestCloneBalance(t *testing.T) {
}
func TestCloneAccountProfile(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Tenant: "cgrates.org",
ID: "Profile_id1",
FilterIDs: []string{"*string:~*req.Account:1001"},
@@ -129,7 +129,7 @@ func TestCloneAccountProfile(t *testing.T) {
}
func TestTenantIDAccountProfile(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Tenant: "cgrates.org",
ID: "test_ID1",
}
@@ -140,7 +140,7 @@ func TestTenantIDAccountProfile(t *testing.T) {
}
func TestAccountProfileAsAccountProfile(t *testing.T) {
apiAccPrf := &APIAccountProfile{
apiAccPrf := &APIAccount{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]interface{}{},
@@ -158,7 +158,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) {
},
Weights: ";10",
}
expected := &AccountProfile{
expected := &Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]interface{}{},
@@ -184,7 +184,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) {
},
},
}
if rcv, err := apiAccPrf.AsAccountProfile(); err != nil {
if rcv, err := apiAccPrf.AsAccount(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcv) {
t.Errorf("Expected %+v, received %+v", ToJSON(expected), ToJSON(rcv))
@@ -192,7 +192,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) {
}
func TestAsAccountProfileError(t *testing.T) {
apiAccPrf := &APIAccountProfile{
apiAccPrf := &APIAccount{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]interface{}{},
@@ -204,14 +204,14 @@ func TestAsAccountProfileError(t *testing.T) {
Weights: "10",
}
expectedErr := "invalid DynamicWeight format for string <10>"
if _, err := apiAccPrf.AsAccountProfile(); err == nil || err.Error() != expectedErr {
if _, err := apiAccPrf.AsAccount(); err == nil || err.Error() != expectedErr {
t.Errorf("Expected %+v, received %+v", expectedErr, err)
}
apiAccPrf.Weights = ";10"
apiAccPrf.Balances["MonetaryBalance"].Weights = "10"
expectedErr = "invalid DynamicWeight format for string <10>"
if _, err := apiAccPrf.AsAccountProfile(); err == nil || err.Error() != expectedErr {
if _, err := apiAccPrf.AsAccount(); err == nil || err.Error() != expectedErr {
t.Errorf("Expected %+v, received %+v", expectedErr, err)
}
}
@@ -267,7 +267,7 @@ func TestAPIBalanceAsBalance(t *testing.T) {
}
func TestAccountProfileBalancesAlteredCompareLength(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Balances: map[string]*Balance{
"testString": {},
"testString2": {},
@@ -286,7 +286,7 @@ func TestAccountProfileBalancesAlteredCompareLength(t *testing.T) {
}
func TestAccountProfileBalancesAlteredCheckKeys(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Balances: map[string]*Balance{
"testString": {},
},
@@ -304,7 +304,7 @@ func TestAccountProfileBalancesAlteredCheckKeys(t *testing.T) {
}
func TestAccountProfileBalancesAlteredCompareValues(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Balances: map[string]*Balance{
"testString": {
Units: &Decimal{decimal.New(1, 1)},
@@ -324,7 +324,7 @@ func TestAccountProfileBalancesAlteredCompareValues(t *testing.T) {
}
func TestAccountProfileBalancesAlteredFalse(t *testing.T) {
actPrf := &AccountProfile{}
actPrf := &Account{}
actBk := AccountBalancesBackup{}
@@ -336,7 +336,7 @@ func TestAccountProfileBalancesAlteredFalse(t *testing.T) {
}
func TestAPRestoreFromBackup(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Balances: map[string]*Balance{
"testString": {
Units: &Decimal{},
@@ -357,7 +357,7 @@ func TestAPRestoreFromBackup(t *testing.T) {
}
func TestAPAccountBalancesBackup(t *testing.T) {
actPrf := &AccountProfile{
actPrf := &Account{
Balances: map[string]*Balance{
"testKey": {
Units: &Decimal{decimal.New(1234, 3)},
@@ -410,7 +410,7 @@ func TestAPNewDefaultBalance(t *testing.T) {
func TestAPApsSort(t *testing.T) {
apS := AccountProfilesWithWeight{
apS := AccountsWithWeight{
{
Weight: 2,
},
@@ -421,7 +421,7 @@ func TestAPApsSort(t *testing.T) {
Weight: 3,
},
}
expected := AccountProfilesWithWeight{
expected := AccountsWithWeight{
{
Weight: 3,
},
@@ -441,9 +441,9 @@ func TestAPApsSort(t *testing.T) {
func TestAPAccountProfiles(t *testing.T) {
apS := AccountProfilesWithWeight{
apS := AccountsWithWeight{
{
AccountProfile: &AccountProfile{
Account: &Account{
Tenant: "testTenant1",
ID: "testID1",
FilterIDs: []string{"testFID1", "testFID2"},
@@ -464,7 +464,7 @@ func TestAPAccountProfiles(t *testing.T) {
LockID: "testString1",
},
{
AccountProfile: &AccountProfile{
Account: &Account{
Tenant: "testTenant2",
ID: "testID2",
FilterIDs: []string{"testFID1", "testFID2"},
@@ -486,9 +486,9 @@ func TestAPAccountProfiles(t *testing.T) {
},
}
expected := make([]*AccountProfile, 0)
expected := make([]*Account, 0)
for i := range apS {
expected = append(expected, apS[i].AccountProfile)
expected = append(expected, apS[i].Account)
}
received := apS.AccountProfiles()
@@ -498,9 +498,9 @@ func TestAPAccountProfiles(t *testing.T) {
}
func TestAPLockIDs(t *testing.T) {
apS := AccountProfilesWithWeight{
apS := AccountsWithWeight{
{
AccountProfile: &AccountProfile{
Account: &Account{
Tenant: "testTenant1",
ID: "testID1",
FilterIDs: []string{"testFID1", "testFID2"},
@@ -521,7 +521,7 @@ func TestAPLockIDs(t *testing.T) {
LockID: "testString1",
},
{
AccountProfile: &AccountProfile{
Account: &Account{
Tenant: "testTenant2",
ID: "testID2",
FilterIDs: []string{"testFID1", "testFID2"},

View File

@@ -38,7 +38,7 @@ type EventCharges struct {
Concretes *Decimal // total concrete units charged
ChargingIntervals []*ChargingInterval
Accounts []*AccountProfile
Accounts []*Account
Accounting map[string]*AccountCharge
UnitFactors map[string]*UnitFactor