Files
prime-sdk-go/transactiontype/transactiontype.go

56 lines
1.5 KiB
Go
Executable File

package transactiontype
import (
"context"
"fmt"
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
)
type TransactionTypeClient struct {
client *client.Client
}
func NewTransactionTypeClient(c *client.Client) *TransactionTypeClient {
return &TransactionTypeClient{client: c}
}
func (ttc *TransactionTypeClient) Create(ctx context.Context, req *models.TransactionTypeCreateRequest) (*models.TransactionTypeCreateResponse, error) {
var resp models.TransactionTypeCreateResponse
err := ttc.client.Post(ctx, "/api/v1/transaction-type", models.ContentTypeJSON, req, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) Get(ctx context.Context, txnType string) (*models.TransactionType, error) {
var resp models.TransactionType
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
err := ttc.client.Get(ctx, path, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) List(ctx context.Context) (*models.TransactionListResponse, error) {
var resp models.TransactionListResponse
err := ttc.client.Get(ctx, "/api/v1/transaction-types", &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (ttc *TransactionTypeClient) Delete(ctx context.Context, txnType string) (*models.SuccessResponse, error) {
var resp models.SuccessResponse
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
err := ttc.client.Delete(ctx, path, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}