mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding TP APIs
This commit is contained in:
42
apier/tp.go
Normal file
42
apier/tp.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2013 ITsysCOM
|
||||
|
||||
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 apier
|
||||
|
||||
// Tariff plan related APIs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type AttrGetTPIds struct {
|
||||
}
|
||||
|
||||
// Queries tarrif plan identities gathered from all tables.
|
||||
func (self *Apier) GetTPIds(attrs AttrGetTPIds, reply *[]string) error {
|
||||
if ids, err := self.StorDb.GetTPIds(); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
} else {
|
||||
*reply = ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -37,10 +37,25 @@ CREATE TABLE `tp_rates` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` char(40) NOT NULL,
|
||||
`tag` varchar(24) NOT NULL,
|
||||
`destinations_tag` varchar(24) NOT NULL,
|
||||
`connect_fee` DECIMAL(5,4) NOT NULL,
|
||||
`rate` DECIMAL(5,4) NOT NULL,
|
||||
`rated_units` INT(11) NOT NULL,
|
||||
`rate_increments` INT(11) NOT NULL,
|
||||
`weight` DECIMAL(5,2) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `destination_rates`
|
||||
--
|
||||
|
||||
CREATE TABLE `tp_destination_rates` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` char(40) NOT NULL,
|
||||
`tag` varchar(24) NOT NULL,
|
||||
`destinations_tag` varchar(24) NOT NULL,
|
||||
`rates_tag` varchar(24) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
@@ -49,11 +64,11 @@ CREATE TABLE `tp_rates` (
|
||||
-- Table structure for table `tp_rate_timings`
|
||||
--
|
||||
|
||||
CREATE TABLE `tp_rate_timings` (
|
||||
CREATE TABLE `tp_destination_rate_timings` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` char(40) NOT NULL,
|
||||
`tag` varchar(24) NOT NULL,
|
||||
`rates_tag` varchar(24) NOT NULL,
|
||||
`destination_rates_tag` varchar(24) NOT NULL,
|
||||
`timings_tag` varchar(24) NOT NULL,
|
||||
`weight` DECIMAL(5,2) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
|
||||
49
docs/api_tp.rst
Normal file
49
docs/api_tp.rst
Normal file
@@ -0,0 +1,49 @@
|
||||
Apier.GetTPDestinationIds
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
// Queries tarrif plan identities gathered from all tables.
|
||||
|
||||
**Request**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
type AttrGetTPIds struct {
|
||||
}
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"id": 9,
|
||||
"method": "Apier.GetTPIds",
|
||||
"params": []
|
||||
}
|
||||
|
||||
|
||||
**Reply**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
[]string
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"error": null,
|
||||
"id": 9,
|
||||
"result": [
|
||||
"SAMPLE_TP",
|
||||
"SAMPLE_TP_2"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
**Errors**:
|
||||
|
||||
``SERVER_ERROR`` - Server error occurred.
|
||||
|
||||
``NOT_FOUND`` - No tariff plans defined.
|
||||
@@ -121,6 +121,15 @@ FlushCache
|
||||
|
||||
These operate on a tpid
|
||||
|
||||
TariffPlan
|
||||
~~~~~~~~~~
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api_tp
|
||||
|
||||
|
||||
Destinations
|
||||
~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ type DataStorage interface {
|
||||
GetDestination(string) (*Destination, error)
|
||||
SetDestination(*Destination) error
|
||||
// Apier functions
|
||||
GetTPIds() ([]string, error)
|
||||
SetTPTiming(string, *Timing) error
|
||||
ExistsTPTiming(string, string) (bool, error)
|
||||
GetTPTiming(string, string) (*Timing, error)
|
||||
|
||||
@@ -73,6 +73,10 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetTPIds() ([]string, error) {
|
||||
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetTPTiming(tpid string, tm *Timing) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
@@ -147,6 +147,10 @@ func (ms *MongoStorage) SetDestination(dest *Destination) error {
|
||||
return ms.db.C("destinations").Insert(dest)
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTPIds() ([]string, error) {
|
||||
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetTPTiming(tpid string, tm *Timing) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetTPIds() ([]string, error) {
|
||||
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetTPTiming(tpid string, tm *Timing) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,31 @@ func (self *SQLStorage) SetDestination(d *Destination) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Return a list with all TPids defined in the system, even if incomplete, isolated in some table.
|
||||
func (self *SQLStorage) GetTPIds() ([]string, error) {
|
||||
rows, err := self.Db.Query(
|
||||
fmt.Sprintf("(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)", utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_RATES, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_DESTINATION_RATE_TIMINGS, utils.TBL_TP_RATE_PROFILES))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
ids := []string{}
|
||||
i := 0
|
||||
for rows.Next() {
|
||||
i++ //Keep here a reference so we know we got at least one
|
||||
var id string
|
||||
err = rows.Scan(&id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if i == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetTPTiming(tpid string, tm *Timing) error {
|
||||
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s')",
|
||||
utils.TBL_TP_TIMINGS, tpid, tm.Id, tm.Years.Serialize(";"), tm.Months.Serialize(";"), tm.MonthDays.Serialize(";"),
|
||||
|
||||
Reference in New Issue
Block a user