Skip to content

Commit

Permalink
Enable listing of database events
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Bhardwaj committed Apr 10, 2024
1 parent f82e947 commit 2ddaa31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type DatabasesService interface {
UpdateTopic(context.Context, string, string, *DatabaseUpdateTopicRequest) (*Response, error)
GetMetricsCredentials(context.Context) (*DatabaseMetricsCredentials, *Response, error)
UpdateMetricsCredentials(context.Context, *DatabaseUpdateMetricsCredentialsRequest) (*Response, error)
ListDatabaseEvents(context.Context, string) ([]*DatabaseEvent, *Response, error)
ListDatabaseEvents(context.Context, string, *ListOptions) ([]DatabaseEvent, *Response, error)
}

// DatabasesServiceOp handles communication with the Databases related methods
Expand Down Expand Up @@ -716,7 +716,7 @@ type DatabaseLayout struct {

// ListDatabaseEvents contains a list of project events.
type ListDatabaseEvents struct {
Events []*DatabaseEvent `json:"events"`
Events []DatabaseEvent `json:"events"`
}

// DatbaseEvent contains the information about a Datbase event.
Expand All @@ -728,7 +728,7 @@ type DatabaseEvent struct {
}

type ListDatabaseEventsRoot struct {
Events []*DatabaseEvent `json:"events"`
Events []DatabaseEvent `json:"events"`
}

// URN returns a URN identifier for the database
Expand Down Expand Up @@ -1538,8 +1538,12 @@ func (svc *DatabasesServiceOp) UpdateMetricsCredentials(ctx context.Context, upd
return resp, nil
}

func (svc *DatabasesServiceOp) ListDatabaseEvents(ctx context.Context, databaseID string) ([]*DatabaseEvent, *Response, error) {
func (svc *DatabasesServiceOp) ListDatabaseEvents(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseEvent, *Response, error) {
path := fmt.Sprintf(databaseEvents, databaseID)
path, err := addOptions(path, opts)
if err != nil {
return nil, nil, err
}
root := new(ListDatabaseEventsRoot)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
Expand All @@ -1552,5 +1556,4 @@ func (svc *DatabasesServiceOp) ListDatabaseEvents(ctx context.Context, databaseI
}

return root.Events, resp, nil

}
4 changes: 2 additions & 2 deletions databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3190,7 +3190,7 @@ func TestDatabases_ListDatabaseEvents(t *testing.T) {

path := fmt.Sprintf("/v2/databases/%s/events", dbID)

want := []*DatabaseEvent{
want := []DatabaseEvent{
{
ID: "pe8u2huh",
ServiceName: "customer-events",
Expand All @@ -3215,7 +3215,7 @@ func TestDatabases_ListDatabaseEvents(t *testing.T) {
fmt.Fprint(w, body)
})

got, _, err := client.Databases.ListDatabaseEvents(ctx, dbID)
got, _, err := client.Databases.ListDatabaseEvents(ctx, dbID, &ListOptions{})
require.NoError(t, err)
require.Equal(t, want, got)
}

0 comments on commit 2ddaa31

Please sign in to comment.