Enable request timeout and cancellation control by adding context.Context as the first parameter to all SDK API methods. This allows users to: - Set per-request timeouts - Cancel in-flight requests - Pass request-scoped values
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package transactiontype
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
|
"git.dragonchain.com/dragonchain/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
|
|
}
|