From 3162462d477618b3266cede2057cb8dd462d19d2 Mon Sep 17 00:00:00 2001 From: andronache Date: Thu, 3 Dec 2020 17:02:53 +0200 Subject: [PATCH] Modified models.go structs to be more intuitive --- apier/v1/apier.go | 8 +-- engine/model_helpers.go | 50 ++++++++-------- engine/model_helpers_test.go | 111 ++++++++++++++++++++--------------- engine/models.go | 24 ++++++-- engine/storage_csv.go | 24 ++++---- engine/storage_sql.go | 16 ++--- loaders/loader.go | 16 ++--- 7 files changed, 141 insertions(+), 108 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index d639109f4..ac04524aa 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1492,7 +1492,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TPAttributes{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.AttributeMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1530,7 +1530,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TPChargers{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.ChargerMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1568,7 +1568,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TPDispatcherProfiles{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.DispatcherProfileMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1606,7 +1606,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TPDispatcherHosts{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.DispatcherHostMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 7476bb6c8..160586408 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2182,15 +2182,15 @@ func RouteProfileToAPI(rp *RouteProfile) (tpRp *utils.TPRouteProfile) { return } -type TPAttributes []*TPAttributeMdl +type AttributeMdls []*AttributeMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TPAttributes) CSVHeader() (result []string) { +func (tps AttributeMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.AttributeFilterIDs, utils.Path, utils.Type, utils.Value, utils.Blocker, utils.Weight} } -func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttributeProfile) { +func (tps AttributeMdls) AsTPAttributes() (result []*utils.TPAttributeProfile) { mst := make(map[string]*utils.TPAttributeProfile) filterMap := make(map[string]utils.StringMap) contextMap := make(map[string]utils.StringMap) @@ -2268,12 +2268,12 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttributeProfile) { return } -func APItoModelTPAttribute(th *utils.TPAttributeProfile) (mdls TPAttributes) { +func APItoModelTPAttribute(th *utils.TPAttributeProfile) (mdls AttributeMdls) { if len(th.Attributes) == 0 { return } for i, reqAttribute := range th.Attributes { - mdl := &TPAttributeMdl{ + mdl := &AttributeMdl{ Tpid: th.TPid, Tenant: th.Tenant, ID: th.ID, @@ -2394,15 +2394,15 @@ func AttributeProfileToAPI(attrPrf *AttributeProfile) (tpAttr *utils.TPAttribute return } -type TPChargers []*TPChargerMdl +type ChargerMdls []*ChargerMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TPChargers) CSVHeader() (result []string) { +func (tps ChargerMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.RunID, utils.AttributeIDs, utils.Weight} } -func (tps TPChargers) AsTPChargers() (result []*utils.TPChargerProfile) { +func (tps ChargerMdls) AsTPChargers() (result []*utils.TPChargerProfile) { mst := make(map[string]*utils.TPChargerProfile) filterMap := make(map[string]utils.StringMap) attributeMap := make(map[string][]string) @@ -2479,7 +2479,7 @@ func (tps TPChargers) AsTPChargers() (result []*utils.TPChargerProfile) { return } -func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls TPChargers) { +func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls ChargerMdls) { if tpCPP != nil { min := len(tpCPP.FilterIDs) isFilter := true @@ -2488,7 +2488,7 @@ func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls TPChargers) { isFilter = false } if min == 0 { - mdl := &TPChargerMdl{ + mdl := &ChargerMdl{ Tenant: tpCPP.Tenant, Tpid: tpCPP.TPid, ID: tpCPP.ID, @@ -2512,7 +2512,7 @@ func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls TPChargers) { mdls = append(mdls, mdl) } else { for i := 0; i < min; i++ { - mdl := &TPChargerMdl{ + mdl := &ChargerMdl{ Tenant: tpCPP.Tenant, Tpid: tpCPP.TPid, ID: tpCPP.ID, @@ -2536,7 +2536,7 @@ func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls TPChargers) { } if len(tpCPP.FilterIDs)-min > 0 { for i := min; i < len(tpCPP.FilterIDs); i++ { - mdl := &TPChargerMdl{ + mdl := &ChargerMdl{ Tenant: tpCPP.Tenant, Tpid: tpCPP.TPid, ID: tpCPP.ID, @@ -2547,7 +2547,7 @@ func APItoModelTPCharger(tpCPP *utils.TPChargerProfile) (mdls TPChargers) { } if len(tpCPP.AttributeIDs)-min > 0 { for i := min; i < len(tpCPP.AttributeIDs); i++ { - mdl := &TPChargerMdl{ + mdl := &ChargerMdl{ Tenant: tpCPP.Tenant, Tpid: tpCPP.TPid, ID: tpCPP.ID, @@ -2611,16 +2611,16 @@ func ChargerProfileToAPI(chargerPrf *ChargerProfile) (tpCharger *utils.TPCharger return } -type TPDispatcherProfiles []*TPDispatcherProfileMdl +type DispatcherProfileMdls []*DispatcherProfileMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TPDispatcherProfiles) CSVHeader() (result []string) { +func (tps DispatcherProfileMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.Subsystems, utils.FilterIDs, utils.ActivationIntervalString, utils.Strategy, utils.StrategyParameters, utils.ConnID, utils.ConnFilterIDs, utils.ConnWeight, utils.ConnBlocker, utils.ConnParameters, utils.Weight} } -func (tps TPDispatcherProfiles) AsTPDispatcherProfiles() (result []*utils.TPDispatcherProfile) { +func (tps DispatcherProfileMdls) AsTPDispatcherProfiles() (result []*utils.TPDispatcherProfile) { mst := make(map[string]*utils.TPDispatcherProfile) filterMap := make(map[string]utils.StringMap) contextMap := make(map[string]utils.StringMap) @@ -2750,7 +2750,7 @@ func paramsToString(sp []interface{}) (strategy string) { return } -func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatcherProfiles) { +func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls DispatcherProfileMdls) { if tpDPP == nil { return } @@ -2771,7 +2771,7 @@ func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls TPDis strategy := paramsToString(tpDPP.StrategyParams) if len(tpDPP.Hosts) == 0 { - return append(mdls, &TPDispatcherProfileMdl{ + return append(mdls, &DispatcherProfileMdl{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, @@ -2787,7 +2787,7 @@ func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls TPDis confilter := strings.Join(tpDPP.Hosts[0].FilterIDs, utils.INFIELD_SEP) conparam := paramsToString(tpDPP.Hosts[0].Params) - mdls = append(mdls, &TPDispatcherProfileMdl{ + mdls = append(mdls, &DispatcherProfileMdl{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, @@ -2807,7 +2807,7 @@ func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls TPDis for i := 1; i < len(tpDPP.Hosts); i++ { confilter = strings.Join(tpDPP.Hosts[i].FilterIDs, utils.INFIELD_SEP) conparam = paramsToString(tpDPP.Hosts[i].Params) - mdls = append(mdls, &TPDispatcherProfileMdl{ + mdls = append(mdls, &DispatcherProfileMdl{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, @@ -2935,14 +2935,14 @@ func DispatcherProfileToAPI(dpp *DispatcherProfile) (tpDPP *utils.TPDispatcherPr } // TPHosts -type TPDispatcherHosts []*TPDispatcherHostMdl +type DispatcherHostMdls []*DispatcherHostMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TPDispatcherHosts) CSVHeader() (result []string) { +func (tps DispatcherHostMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.TLS} } -func (tps TPDispatcherHosts) AsTPDispatcherHosts() (result []*utils.TPDispatcherHost) { +func (tps DispatcherHostMdls) AsTPDispatcherHosts() (result []*utils.TPDispatcherHost) { hostsMap := make(map[string]*utils.TPDispatcherHost) for _, tp := range tps { if len(tp.Address) == 0 { // empty addres do not populate conns @@ -2969,11 +2969,11 @@ func (tps TPDispatcherHosts) AsTPDispatcherHosts() (result []*utils.TPDispatcher return } -func APItoModelTPDispatcherHost(tpDPH *utils.TPDispatcherHost) (mdls *TPDispatcherHostMdl) { +func APItoModelTPDispatcherHost(tpDPH *utils.TPDispatcherHost) (mdls *DispatcherHostMdl) { if tpDPH == nil { return } - return &TPDispatcherHostMdl{ + return &DispatcherHostMdl{ Tpid: tpDPH.TPid, Tenant: tpDPH.Tenant, ID: tpDPH.ID, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index db8dabecd..e0b4294a9 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -2989,8 +2989,8 @@ func TestAPItoModelTPAttribute(t *testing.T) { }, Weight: 20, } - expected := TPAttributes{ - &TPAttributeMdl{ + expected := AttributeMdls{ + &AttributeMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "ALS1", @@ -3031,8 +3031,8 @@ func TestCsvDumpForAttributeModels(t *testing.T) { }, Weight: 20, } - expected := TPAttributes{ - &TPAttributeMdl{ + expected := AttributeMdls{ + &AttributeMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "ALS1", @@ -3043,7 +3043,7 @@ func TestCsvDumpForAttributeModels(t *testing.T) { ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, }, - &TPAttributeMdl{ + &AttributeMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "ALS1", @@ -3068,8 +3068,8 @@ func TestCsvDumpForAttributeModels(t *testing.T) { } func TestModelAsTPAttribute(t *testing.T) { - models := TPAttributes{ - &TPAttributeMdl{ + models := AttributeMdls{ + &AttributeMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "ALS1", @@ -3205,8 +3205,8 @@ func TestAPItoModelTPCharger(t *testing.T) { AttributeIDs: []string{"ATTR1", "ATTR2"}, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3216,7 +3216,7 @@ func TestAPItoModelTPCharger(t *testing.T) { ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, }, - &TPChargerMdl{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3246,8 +3246,8 @@ func TestAPItoModelTPCharger2(t *testing.T) { AttributeIDs: []string{"ATTR1", "ATTR2"}, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3257,7 +3257,7 @@ func TestAPItoModelTPCharger2(t *testing.T) { ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, }, - &TPChargerMdl{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3286,8 +3286,8 @@ func TestAPItoModelTPCharger3(t *testing.T) { AttributeIDs: []string{"ATTR1"}, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3297,7 +3297,7 @@ func TestAPItoModelTPCharger3(t *testing.T) { ActivationInterval: "2014-07-14T14:35:00Z", Weight: 20, }, - &TPChargerMdl{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3324,8 +3324,8 @@ func TestAPItoModelTPCharger4(t *testing.T) { }, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3355,8 +3355,8 @@ func TestAPItoModelTPCharger5(t *testing.T) { AttributeIDs: []string{"ATTR1"}, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3385,8 +3385,8 @@ func TestAPItoModelTPCharger6(t *testing.T) { }, Weight: 20, } - expected := TPChargers{ - &TPChargerMdl{ + expected := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3402,8 +3402,8 @@ func TestAPItoModelTPCharger6(t *testing.T) { } func TestModelAsTPChargers(t *testing.T) { - models := TPChargers{ - &TPChargerMdl{ + models := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3447,8 +3447,8 @@ func TestModelAsTPChargers(t *testing.T) { } func TestModelAsTPChargers2(t *testing.T) { - models := TPChargers{ - &TPChargerMdl{ + models := ChargerMdls{ + &ChargerMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Charger1", @@ -3637,8 +3637,8 @@ func TestAPItoModelTPDispatcher(t *testing.T) { }, }, } - expected := TPDispatcherProfiles{ - &TPDispatcherProfileMdl{ + expected := DispatcherProfileMdls{ + &DispatcherProfileMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -3652,7 +3652,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) { ConnBlocker: false, ConnParameters: "192.168.54.203", }, - &TPDispatcherProfileMdl{ + &DispatcherProfileMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -3669,7 +3669,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) { } func TestTPDispatcherHostsCSVHeader(t *testing.T) { - tps := &TPDispatcherHosts{} + tps := &DispatcherHostMdls{} eOut := []string{"#" + utils.Tenant, utils.ID, utils.Address, utils.Transport, utils.TLS} if rcv := tps.CSVHeader(); !reflect.DeepEqual(rcv, eOut) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) @@ -3677,13 +3677,13 @@ func TestTPDispatcherHostsCSVHeader(t *testing.T) { } func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) { - tps := &TPDispatcherHosts{} + tps := &DispatcherHostMdls{} if rcv := tps.AsTPDispatcherHosts(); rcv != nil { t.Errorf("Expecting: nil,\nReceived: %+v", utils.ToJSON(rcv)) } - tps = &TPDispatcherHosts{ - &TPDispatcherHostMdl{ + tps = &DispatcherHostMdls{ + &DispatcherHostMdl{ ID: "ID1", Tenant: "Tenant1", }} @@ -3691,8 +3691,8 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) { t.Errorf("Expecting: nil,\nReceived: %+v", utils.ToJSON(rcv)) } - tps = &TPDispatcherHosts{ - &TPDispatcherHostMdl{ + tps = &DispatcherHostMdls{ + &DispatcherHostMdl{ Address: "Address1", ID: "ID1", Tenant: "Tenant1", @@ -3712,8 +3712,8 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) } - tps = &TPDispatcherHosts{ - &TPDispatcherHostMdl{ + tps = &DispatcherHostMdls{ + &DispatcherHostMdl{ Address: "Address2", ID: "ID2", Tenant: "Tenant2", @@ -3733,8 +3733,8 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) } - tps = &TPDispatcherHosts{ - &TPDispatcherHostMdl{ + tps = &DispatcherHostMdls{ + &DispatcherHostMdl{ Address: "Address3", ID: "ID3", Tenant: "Tenant3", @@ -3755,8 +3755,8 @@ func TestTPDispatcherHostsAsTPDispatcherHosts(t *testing.T) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) } - tps = &TPDispatcherHosts{ - &TPDispatcherHostMdl{ + tps = &DispatcherHostMdls{ + &DispatcherHostMdl{ Address: "Address4", ID: "ID4", Tenant: "Tenant4", @@ -3794,7 +3794,7 @@ func TestAPItoModelTPDispatcherHost(t *testing.T) { Transport: "*json", }, } - eOut := &TPDispatcherHostMdl{ + eOut := &DispatcherHostMdl{ Address: "Address1", Transport: "*json", Tenant: "Tenant", @@ -5114,8 +5114,8 @@ func TestModelHelpersParamsToString(t *testing.T) { } func TestModelHelpersAsTPDispatcherProfiles(t *testing.T) { - structTest := TPDispatcherProfiles{ - &TPDispatcherProfileMdl{ + structTest := DispatcherProfileMdls{ + &DispatcherProfileMdl{ ActivationInterval: "2014-07-29T15:00:00Z;2014-08-29T15:00:00Z", StrategyParameters: "Param1", }, @@ -5135,8 +5135,8 @@ func TestModelHelpersAsTPDispatcherProfiles(t *testing.T) { } func TestTPDispatcherProfilesCSVHeader(t *testing.T) { - structTest := TPDispatcherProfiles{ - &TPDispatcherProfileMdl{ + structTest := DispatcherProfileMdls{ + &DispatcherProfileMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -5150,7 +5150,7 @@ func TestTPDispatcherProfilesCSVHeader(t *testing.T) { ConnBlocker: false, ConnParameters: "192.168.54.203", }, - &TPDispatcherProfileMdl{ + &DispatcherProfileMdl{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -5252,3 +5252,20 @@ func TestRateProfileMdlsAsTPRateProfileCase2(t *testing.T) { } } + +func TestAPItoModelTPDispatcherProfileCase2(t *testing.T) { + structTest := &utils.TPDispatcherProfile{ + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-29T15:00:00Z", + ExpiryTime: "2014-07-30T15:00:00Z", + }, + } + expStruct := DispatcherProfileMdls{{ + ActivationInterval: "2014-07-29T15:00:00Z;2014-07-30T15:00:00Z", + }, + } + result := APItoModelTPDispatcherProfile(structTest) + if !reflect.DeepEqual(result, expStruct) { + t.Errorf("\nExpecting <%T>,\n Received <%T>", expStruct, result) + } +} diff --git a/engine/models.go b/engine/models.go index a9a80a1db..0479db148 100644 --- a/engine/models.go +++ b/engine/models.go @@ -435,7 +435,7 @@ func (RouteMdl) TableName() string { return utils.TBLTPRoutes } -type TPAttributeMdl struct { +type AttributeMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -452,7 +452,11 @@ type TPAttributeMdl struct { CreatedAt time.Time } -type TPChargerMdl struct { +func (AttributeMdl) TableName() string { + return utils.TBLTPAttributes +} + +type ChargerMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -465,7 +469,11 @@ type TPChargerMdl struct { CreatedAt time.Time } -type TPDispatcherProfileMdl struct { +func (ChargerMdl) TableName() string { + return utils.TBLTPChargers +} + +type DispatcherProfileMdl struct { PK uint `gorm:"primary_key"` Tpid string // Tenant string `index:"0" re:""` @@ -484,7 +492,11 @@ type TPDispatcherProfileMdl struct { CreatedAt time.Time } -type TPDispatcherHostMdl struct { +func (DispatcherProfileMdl) TableName() string { + return utils.TBLTPDispatchers +} + +type DispatcherHostMdl struct { PK uint `gorm:"primary_key"` Tpid string // Tenant string `index:"0" re:""` @@ -495,6 +507,10 @@ type TPDispatcherHostMdl struct { CreatedAt time.Time } +func (DispatcherHostMdl) TableName() string { + return utils.TBLTPDispatcherHosts +} + type RateProfileMdl struct { PK uint `gorm:"primary_key"` Tpid string diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 11dfb1160..665efbc97 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -616,9 +616,9 @@ func (csvs *CSVStorage) GetTPRoutes(tpid, tenant, id string) ([]*utils.TPRoutePr } func (csvs *CSVStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAttributeProfile, error) { - var tpAls TPAttributes - if err := csvs.proccesData(TPAttributeMdl{}, csvs.attributeProfilesFn, func(tp interface{}) { - attributeProfile := tp.(TPAttributeMdl) + var tpAls AttributeMdls + if err := csvs.proccesData(AttributeMdl{}, csvs.attributeProfilesFn, func(tp interface{}) { + attributeProfile := tp.(AttributeMdl) attributeProfile.Tpid = tpid tpAls = append(tpAls, &attributeProfile) }); err != nil { @@ -628,9 +628,9 @@ func (csvs *CSVStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAtt } func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) { - var tpCPPs TPChargers - if err := csvs.proccesData(TPChargerMdl{}, csvs.chargerProfilesFn, func(tp interface{}) { - cpp := tp.(TPChargerMdl) + var tpCPPs ChargerMdls + if err := csvs.proccesData(ChargerMdl{}, csvs.chargerProfilesFn, func(tp interface{}) { + cpp := tp.(ChargerMdl) cpp.Tpid = tpid tpCPPs = append(tpCPPs, &cpp) }); err != nil { @@ -640,9 +640,9 @@ func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg } func (csvs *CSVStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { - var tpDPPs TPDispatcherProfiles - if err := csvs.proccesData(TPDispatcherProfileMdl{}, csvs.dispatcherProfilesFn, func(tp interface{}) { - dpp := tp.(TPDispatcherProfileMdl) + var tpDPPs DispatcherProfileMdls + if err := csvs.proccesData(DispatcherProfileMdl{}, csvs.dispatcherProfilesFn, func(tp interface{}) { + dpp := tp.(DispatcherProfileMdl) dpp.Tpid = tpid tpDPPs = append(tpDPPs, &dpp) }); err != nil { @@ -652,9 +652,9 @@ func (csvs *CSVStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*uti } func (csvs *CSVStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.TPDispatcherHost, error) { - var tpDDHs TPDispatcherHosts - if err := csvs.proccesData(TPDispatcherHostMdl{}, csvs.dispatcherHostsFn, func(tp interface{}) { - dpp := tp.(TPDispatcherHostMdl) + var tpDDHs DispatcherHostMdls + if err := csvs.proccesData(DispatcherHostMdl{}, csvs.dispatcherHostsFn, func(tp interface{}) { + dpp := tp.(DispatcherHostMdl) dpp.Tpid = tpid tpDDHs = append(tpDDHs, &dpp) }); err != nil { diff --git a/engine/storage_sql.go b/engine/storage_sql.go index ed981374d..0c70968f7 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -646,7 +646,7 @@ func (self *SQLStorage) SetTPAttributes(tpAttrs []*utils.TPAttributeProfile) err tx := self.db.Begin() for _, stq := range tpAttrs { // Remove previous - if err := tx.Where(&TPAttributeMdl{Tpid: stq.TPid, ID: stq.ID}).Delete(TPAttributeMdl{}).Error; err != nil { + if err := tx.Where(&AttributeMdl{Tpid: stq.TPid, ID: stq.ID}).Delete(AttributeMdl{}).Error; err != nil { tx.Rollback() return err } @@ -668,7 +668,7 @@ func (self *SQLStorage) SetTPChargers(tpCPPs []*utils.TPChargerProfile) error { tx := self.db.Begin() for _, cpp := range tpCPPs { // Remove previous - if err := tx.Where(&TPChargerMdl{Tpid: cpp.TPid, ID: cpp.ID}).Delete(TPChargerMdl{}).Error; err != nil { + if err := tx.Where(&ChargerMdl{Tpid: cpp.TPid, ID: cpp.ID}).Delete(ChargerMdl{}).Error; err != nil { tx.Rollback() return err } @@ -690,7 +690,7 @@ func (self *SQLStorage) SetTPDispatcherProfiles(tpDPPs []*utils.TPDispatcherProf tx := self.db.Begin() for _, dpp := range tpDPPs { // Remove previous - if err := tx.Where(&TPDispatcherProfileMdl{Tpid: dpp.TPid, ID: dpp.ID}).Delete(TPDispatcherProfileMdl{}).Error; err != nil { + if err := tx.Where(&DispatcherProfileMdl{Tpid: dpp.TPid, ID: dpp.ID}).Delete(DispatcherProfileMdl{}).Error; err != nil { tx.Rollback() return err } @@ -712,7 +712,7 @@ func (self *SQLStorage) SetTPDispatcherHosts(tpDPPs []*utils.TPDispatcherHost) e tx := self.db.Begin() for _, dpp := range tpDPPs { // Remove previous - if err := tx.Where(&TPDispatcherHostMdl{Tpid: dpp.TPid, ID: dpp.ID}).Delete(TPDispatcherHostMdl{}).Error; err != nil { + if err := tx.Where(&DispatcherHostMdl{Tpid: dpp.TPid, ID: dpp.ID}).Delete(DispatcherHostMdl{}).Error; err != nil { tx.Rollback() return err } @@ -1539,7 +1539,7 @@ func (self *SQLStorage) GetTPRoutes(tpid, tenant, id string) ([]*utils.TPRoutePr } func (self *SQLStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAttributeProfile, error) { - var sps TPAttributes + var sps AttributeMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1558,7 +1558,7 @@ func (self *SQLStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAtt } func (self *SQLStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) { - var cpps TPChargers + var cpps ChargerMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1577,7 +1577,7 @@ func (self *SQLStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg } func (self *SQLStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { - var dpps TPDispatcherProfiles + var dpps DispatcherProfileMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1596,7 +1596,7 @@ func (self *SQLStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*uti } func (self *SQLStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.TPDispatcherHost, error) { - var dpps TPDispatcherHosts + var dpps DispatcherHostMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) diff --git a/loaders/loader.go b/loaders/loader.go index 82db30d44..3c557f2a2 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -283,9 +283,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaAttributes: cacheIDs = []string{utils.CacheAttributeFilterIndexes} for _, lDataSet := range lds { - attrModels := make(engine.TPAttributes, len(lDataSet)) + attrModels := make(engine.AttributeMdls, len(lDataSet)) for i, ld := range lDataSet { - attrModels[i] = new(engine.TPAttributeMdl) + attrModels[i] = new(engine.AttributeMdl) if err = utils.UpdateStructWithIfaceMap(attrModels[i], ld); err != nil { return } @@ -490,9 +490,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaChargers: cacheIDs = []string{utils.CacheChargerFilterIndexes} for _, lDataSet := range lds { - cppModels := make(engine.TPChargers, len(lDataSet)) + cppModels := make(engine.ChargerMdls, len(lDataSet)) for i, ld := range lDataSet { - cppModels[i] = new(engine.TPChargerMdl) + cppModels[i] = new(engine.ChargerMdl) if err = utils.UpdateStructWithIfaceMap(cppModels[i], ld); err != nil { return } @@ -520,9 +520,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaDispatchers: cacheIDs = []string{utils.CacheDispatcherFilterIndexes} for _, lDataSet := range lds { - dispModels := make(engine.TPDispatcherProfiles, len(lDataSet)) + dispModels := make(engine.DispatcherProfileMdls, len(lDataSet)) for i, ld := range lDataSet { - dispModels[i] = new(engine.TPDispatcherProfileMdl) + dispModels[i] = new(engine.DispatcherProfileMdl) if err = utils.UpdateStructWithIfaceMap(dispModels[i], ld); err != nil { return } @@ -548,9 +548,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, } case utils.MetaDispatcherHosts: for _, lDataSet := range lds { - dispModels := make(engine.TPDispatcherHosts, len(lDataSet)) + dispModels := make(engine.DispatcherHostMdls, len(lDataSet)) for i, ld := range lDataSet { - dispModels[i] = new(engine.TPDispatcherHostMdl) + dispModels[i] = new(engine.DispatcherHostMdl) if err = utils.UpdateStructWithIfaceMap(dispModels[i], ld); err != nil { return }