Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
All notable changes to this project will be documented in this file.
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/).

## 0.27.0

### Updated

* Splitting Fixed Subscription structs into response and request structs, as JSON fields differ between the two uses.

## 0.26.0

### Fixed

* Fixes to the AA regions endpoint: removing the unfilled RegionId field and correcting the JSON for the DeploymentCidr field.

## 0.25.0

### Added

* Added payment method to the fixed subscription API. This should allow payments via the marketplace as well as credit cards.

## 0.24.0

### Added
*
* Add endpoint for Active Active regions.

## 0.23.0

### Added

* Add Query Performance Factor property to subscription and database models

## 0.22.0
Expand Down
13 changes: 8 additions & 5 deletions fixed_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestFixedSubscription_Create(t *testing.T) {

actual, err := subject.FixedSubscriptions.Create(
context.TODO(),
fixedSubscriptions.FixedSubscription{
fixedSubscriptions.FixedSubscriptionRequest{
Name: redis.String("My test fixed subscription"),
PlanId: redis.Int(34858),
PaymentMethodID: redis.Int(30949),
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestFixedSubscription_Create_Marketplace(t *testing.T) {

actual, err := subject.FixedSubscriptions.Create(
context.TODO(),
fixedSubscriptions.FixedSubscription{
fixedSubscriptions.FixedSubscriptionRequest{
Name: redis.String("My test fixed subscription with marketplace payments"),
PlanId: redis.Int(34811),
PaymentMethod: redis.String("marketplace"),
Expand Down Expand Up @@ -274,13 +274,14 @@ func TestFixedSubscription_List(t *testing.T) {
actual, err := subject.FixedSubscriptions.List(context.TODO())
require.NoError(t, err)

assert.ElementsMatch(t, []*fixedSubscriptions.FixedSubscription{
assert.ElementsMatch(t, []*fixedSubscriptions.FixedSubscriptionResponse{
{
ID: redis.Int(111614),
Name: redis.String("My test fixed subscription"),
Status: redis.String("active"),
PlanId: redis.Int(34858),
PaymentMethodID: redis.Int(30949),
PaymentMethod: redis.String("credit-card"),
CreationDate: redis.Time(time.Date(2024, 5, 9, 9, 36, 18, 0, time.UTC)),
},
{
Expand All @@ -289,6 +290,7 @@ func TestFixedSubscription_List(t *testing.T) {
Status: redis.String("active"),
PlanId: redis.Int(34858),
PaymentMethodID: redis.Int(30949),
PaymentMethod: redis.String("credit-card"),
CreationDate: redis.Time(time.Date(2024, 5, 9, 10, 49, 52, 0, time.UTC)),
},
}, actual)
Expand Down Expand Up @@ -345,11 +347,12 @@ func TestFixedSubscription_Get(t *testing.T) {
actual, err := subject.FixedSubscriptions.Get(context.TODO(), 111614)
require.NoError(t, err)

assert.Equal(t, &fixedSubscriptions.FixedSubscription{
assert.Equal(t, &fixedSubscriptions.FixedSubscriptionResponse{
ID: redis.Int(111614),
Name: redis.String("My test fixed subscription"),
Status: redis.String("active"),
PlanId: redis.Int(34858),
PaymentMethod: redis.String("credit-card"),
PaymentMethodID: redis.Int(30949),
CreationDate: redis.Time(time.Date(2024, 5, 9, 9, 36, 18, 0, time.UTC)),
}, actual)
Expand Down Expand Up @@ -439,7 +442,7 @@ func TestFixedSubscription_Update(t *testing.T) {
err = subject.FixedSubscriptions.Update(
context.TODO(),
111614,
fixedSubscriptions.FixedSubscription{
fixedSubscriptions.FixedSubscriptionRequest{
Name: redis.String("My renamed fixed subscription"),
PlanId: redis.Int(34853),
},
Expand Down
27 changes: 20 additions & 7 deletions service/fixed/subscriptions/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,35 @@ import (
"github.com/RedisLabs/rediscloud-go-api/internal"
)

type FixedSubscription struct {
ID *int `json:"id,omitempty"` // Omit for Create and Update
// Represents request information to create/update a fixed subscription
type FixedSubscriptionRequest struct {
Name *string `json:"name,omitempty"`
PlanId *int `json:"planId,omitempty"`
PaymentMethod *string `json:"paymentMethod,omitempty"`
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
}

// Represents subscription info response from the get/list endpoints
type FixedSubscriptionResponse struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Status *string `json:"status,omitempty"` // Omit for Create and Update
Status *string `json:"status,omitempty"`
PlanId *int `json:"planId,omitempty"`
PaymentMethod *string `json:"paymentMethod,omitempty"`
PaymentMethod *string `json:"paymentMethodType,omitempty"`
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
CreationDate *time.Time `json:"creationDate,omitempty"` // Omit for Create and Update
CreationDate *time.Time `json:"creationDate,omitempty"`
}

func (o FixedSubscriptionRequest) String() string {
return internal.ToString(o)
}

func (o FixedSubscription) String() string {
func (o FixedSubscriptionResponse) String() string {
return internal.ToString(o)
}

type listFixedSubscriptionResponse struct {
FixedSubscriptions []*FixedSubscription `json:"subscriptions"`
FixedSubscriptions []*FixedSubscriptionResponse `json:"subscriptions"`
}

type NotFound struct {
Expand Down
10 changes: 5 additions & 5 deletions service/fixed/subscriptions/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewAPI(client HttpClient, taskWaiter TaskWaiter, logger Log) *API {
}

// Create will create a new subscription.
func (a *API) Create(ctx context.Context, subscription FixedSubscription) (int, error) {
func (a *API) Create(ctx context.Context, subscription FixedSubscriptionRequest) (int, error) {
var task internal.TaskResponse
err := a.client.Post(ctx, "create fixed subscription", "/fixed/subscriptions", subscription, &task)
if err != nil {
Expand All @@ -53,7 +53,7 @@ func (a *API) Create(ctx context.Context, subscription FixedSubscription) (int,
}

// List will list all of the current account's fixed subscriptions.
func (a *API) List(ctx context.Context) ([]*FixedSubscription, error) {
func (a *API) List(ctx context.Context) ([]*FixedSubscriptionResponse, error) {
var response listFixedSubscriptionResponse
err := a.client.Get(ctx, "list fixed subscriptions", "/fixed/subscriptions", &response)
if err != nil {
Expand All @@ -64,8 +64,8 @@ func (a *API) List(ctx context.Context) ([]*FixedSubscription, error) {
}

// Get will retrieve an existing fixed subscription.
func (a *API) Get(ctx context.Context, id int) (*FixedSubscription, error) {
var response FixedSubscription
func (a *API) Get(ctx context.Context, id int) (*FixedSubscriptionResponse, error) {
var response FixedSubscriptionResponse
err := a.client.Get(ctx, fmt.Sprintf("retrieve fixed subscription %d", id), fmt.Sprintf("/fixed/subscriptions/%d", id), &response)
if err != nil {
return nil, wrap404Error(id, err)
Expand All @@ -75,7 +75,7 @@ func (a *API) Get(ctx context.Context, id int) (*FixedSubscription, error) {
}

// Update will make changes to an existing fixed subscription.
func (a *API) Update(ctx context.Context, id int, subscription FixedSubscription) error {
func (a *API) Update(ctx context.Context, id int, subscription FixedSubscriptionRequest) error {
var task internal.TaskResponse
err := a.client.Put(ctx, fmt.Sprintf("update fixed subscription %d", id), fmt.Sprintf("/fixed/subscriptions/%d", id), subscription, &task)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func TestSubscription_List(t *testing.T) {
"id": 1,
"name": "sdk",
"status": "active",
"paymentMethodType": "credit-card",
"paymentMethodId": 2,
"paymentMethodType": "credit-card",
"memoryStorage": "ram",
"storageEncryption": false,
"numberOfDatabases": 1,
Expand Down Expand Up @@ -210,6 +210,7 @@ func TestSubscription_List(t *testing.T) {
"name": "TF Example Subscription demo",
"status": "pending",
"paymentMethodId": 3,
"paymentMethodType": "credit-card",
"memoryStorage": "ram",
"storageEncryption": false,
"numberOfDatabases": 0,
Expand Down Expand Up @@ -260,8 +261,8 @@ func TestSubscription_List(t *testing.T) {
ID: redis.Int(1),
Name: redis.String("sdk"),
Status: redis.String("active"),
PaymentMethod: redis.String("credit-card"),
PaymentMethodID: redis.Int(2),
PaymentMethod: redis.String("credit-card"),
MemoryStorage: redis.String("ram"),
StorageEncryption: redis.Bool(false),
NumberOfDatabases: redis.Int(1),
Expand Down Expand Up @@ -291,6 +292,7 @@ func TestSubscription_List(t *testing.T) {
Name: redis.String("TF Example Subscription demo"),
Status: redis.String("pending"),
PaymentMethodID: redis.Int(3),
PaymentMethod: redis.String("credit-card"),
MemoryStorage: redis.String("ram"),
StorageEncryption: redis.Bool(false),
NumberOfDatabases: redis.Int(0),
Expand Down
Loading