mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Finishing TPActions API methods and adding their documentation
This commit is contained in:
@@ -55,7 +55,7 @@ type AttrGetTPActions struct {
|
||||
ActionsId string // Actions id
|
||||
}
|
||||
|
||||
// Queries specific Actions on tariff plan
|
||||
// Queries specific Actions profile on tariff plan
|
||||
func (self *Apier) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
|
||||
234
docs/api_tpactions.rst
Normal file
234
docs/api_tpactions.rst
Normal file
@@ -0,0 +1,234 @@
|
||||
Apier.SetTPActions
|
||||
++++++++++++++++++
|
||||
|
||||
Creates a new Actions profile within a tariff plan.
|
||||
|
||||
**Request**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
type TPActions struct {
|
||||
TPid string // Tariff plan id
|
||||
ActionsId string // Actions id
|
||||
Actions []Action // Set of actions this Actions profile will perform
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
Identifier string // Identifier mapped in the code
|
||||
BalanceId string // Type of balance the action will operate on
|
||||
Direction string // Balance direction
|
||||
Units float64 // Number of units to add/deduct
|
||||
ExpirationTime int64 // Time when the units will expire
|
||||
DestinationId string // Destination profile id
|
||||
RateType string // Type of price <ABSOLUTE|PERCENT>
|
||||
Rate float64 // Price value
|
||||
MinutesWeight float64 // Minutes weight
|
||||
Weight float64 // Action's weight
|
||||
}
|
||||
|
||||
Mandatory parameters: ``[]string{"TPid", "ActionsId", "Actions", "Identifier", "Weight"}``
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"id": 3,
|
||||
"method": "Apier.SetTPActions",
|
||||
"params": [
|
||||
{
|
||||
"Actions": [
|
||||
{
|
||||
"BalanceId": "MONEY",
|
||||
"DestinationId": "CGRATES_NET",
|
||||
"Direction": "OUT",
|
||||
"ExpirationTime": 1374082259,
|
||||
"Identifier": "TOPUP_RESET",
|
||||
"MinutesWeight": 10,
|
||||
"Rate": 0.12,
|
||||
"RateType": "ABSOLUTE",
|
||||
"Units": 10,
|
||||
"Weight": 10
|
||||
}
|
||||
],
|
||||
"ActionsId": "SAMPLE_ACTS_1",
|
||||
"TPid": "SAMPLE_TP_1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
**Reply**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
string
|
||||
|
||||
Possible answers:
|
||||
``OK`` - Success.
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"error": null,
|
||||
"id": 3,
|
||||
"result": "OK"
|
||||
}
|
||||
|
||||
**Errors**:
|
||||
|
||||
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
|
||||
|
||||
``SERVER_ERROR`` - Server error occurred.
|
||||
|
||||
``DUPLICATE`` - The specified combination of TPid/ActionsId already present in StorDb.
|
||||
|
||||
|
||||
Apier.GetTPActions
|
||||
++++++++++++++++++
|
||||
|
||||
Queries specific Actions profile on tariff plan.
|
||||
|
||||
**Request**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
type AttrGetTPActions struct {
|
||||
TPid string // Tariff plan id
|
||||
ActionsId string // Actions id
|
||||
}
|
||||
|
||||
Mandatory parameters: ``[]string{"TPid", "ActionsId"}``
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"id": 5,
|
||||
"method": "Apier.GetTPActions",
|
||||
"params": [
|
||||
{
|
||||
"ActionsId": "SAMPLE_ACTS_1",
|
||||
"TPid": "SAMPLE_TP_1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
**Reply**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
type TPActions struct {
|
||||
TPid string // Tariff plan id
|
||||
ActionsId string // Actions id
|
||||
Actions []Action // Set of actions this Actions profile will perform
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
Identifier string // Identifier mapped in the code
|
||||
BalanceId string // Type of balance the action will operate on
|
||||
Direction string // Balance direction
|
||||
Units float64 // Number of units to add/deduct
|
||||
ExpirationTime int64 // Time when the units will expire
|
||||
DestinationId string // Destination profile id
|
||||
RateType string // Type of price <ABSOLUTE|PERCENT>
|
||||
Rate float64 // Price value
|
||||
MinutesWeight float64 // Minutes weight
|
||||
Weight float64 // Action's weight
|
||||
}
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"error": null,
|
||||
"id": 5,
|
||||
"result": {
|
||||
"Actions": [
|
||||
{
|
||||
"BalanceId": "MONEY",
|
||||
"DestinationId": "CGRATES_NET",
|
||||
"Direction": "OUT",
|
||||
"ExpirationTime": 1374082259,
|
||||
"Identifier": "TOPUP_RESET",
|
||||
"MinutesWeight": 10,
|
||||
"Rate": 0.12,
|
||||
"RateType": "ABSOLUTE",
|
||||
"Units": 10,
|
||||
"Weight": 10
|
||||
}
|
||||
],
|
||||
"ActionsId": "SAMPLE_ACTS_1",
|
||||
"TPid": "SAMPLE_TP_1"
|
||||
}
|
||||
}
|
||||
|
||||
**Errors**:
|
||||
|
||||
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
|
||||
|
||||
``SERVER_ERROR`` - Server error occurred.
|
||||
|
||||
``NOT_FOUND`` - Requested Actions profile not found.
|
||||
|
||||
|
||||
Apier.GetTPActionIds
|
||||
++++++++++++++++++++
|
||||
|
||||
Queries Actions identities on specific tariff plan.
|
||||
|
||||
**Request**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
type AttrGetTPActionIds struct {
|
||||
TPid string // Tariff plan id
|
||||
}
|
||||
|
||||
Mandatory parameters: ``[]string{"TPid"}``
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"id": 6,
|
||||
"method": "Apier.GetTPActionIds",
|
||||
"params": [
|
||||
{
|
||||
"TPid": "SAMPLE_TP_1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
**Reply**:
|
||||
|
||||
Data:
|
||||
::
|
||||
|
||||
[]string
|
||||
|
||||
*JSON sample*:
|
||||
::
|
||||
|
||||
{
|
||||
"error": null,
|
||||
"id": 6,
|
||||
"result": [
|
||||
"SAMPLE_ACTS_1",
|
||||
"SAMPLE_ACTS_2"
|
||||
]
|
||||
}
|
||||
|
||||
**Errors**:
|
||||
|
||||
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
|
||||
|
||||
``SERVER_ERROR`` - Server error occurred.
|
||||
|
||||
``NOT_FOUND`` - There are no Actions profiles defined on the selected TPid.
|
||||
|
||||
|
||||
@@ -183,6 +183,14 @@ RateProfiles
|
||||
|
||||
api_tprateprofiles
|
||||
|
||||
Actions
|
||||
~~~~~~~~~~~~
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api_actions
|
||||
|
||||
|
||||
6.1.5. Management API
|
||||
---------------------
|
||||
|
||||
@@ -540,12 +540,50 @@ func (self *SQLStorage) SetTPActions(acts *utils.TPActions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPActions(tpid, aId string) (*utils.TPActions, error) {
|
||||
return nil, nil
|
||||
func (self *SQLStorage) GetTPActions(tpid, actsId string) (*utils.TPActions, error) {
|
||||
rows, err := self.Db.Query(fmt.Sprintf("SELECT action,balance_tag,direction,units,expiration_time,destination_tag,rate_type,rate, minutes_weight,weight FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_ACTIONS, tpid, actsId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
acts := &utils.TPActions{TPid: tpid, ActionsId: actsId}
|
||||
i := 0
|
||||
for rows.Next() {
|
||||
i++ //Keep here a reference so we know we got at least one result
|
||||
var action, balanceId, dir, destId, rateType string
|
||||
var expTime int64
|
||||
var units, rate, minutesWeight, weight float64
|
||||
if err = rows.Scan(&action, &balanceId, &dir, &units, &expTime, &destId, &rateType, &rate, &minutesWeight, &weight); err!= nil {
|
||||
return nil, err
|
||||
}
|
||||
acts.Actions = append(acts.Actions, utils.Action{action, balanceId, dir, units, expTime, destId, rateType, rate, minutesWeight, weight})
|
||||
}
|
||||
if i == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return acts, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPActionIds(tpid string) ([]string, error) {
|
||||
return nil, nil
|
||||
rows, err := self.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_ACTIONS, tpid))
|
||||
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
|
||||
if err = rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if i == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetActions(string) (as Actions, err error) {
|
||||
|
||||
Reference in New Issue
Block a user