Skip to content

Commit

Permalink
refactor: Improve exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaspt committed Nov 12, 2024
1 parent c9002ee commit 0d2d9a1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type Invitation struct {
UpdatedAt int64 `json:"updated_at"`
}

type Invitations struct {
APIResource
Invitations []*Invitation `json:"data"`
}

type InvitationList struct {
APIResource
Invitations []*Invitation `json:"data"`
Expand Down
2 changes: 1 addition & 1 deletion invitation/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions invitation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,29 @@ func (b BulkCreateParams) MarshalJSON() ([]byte, error) {
return json.Marshal(b.Invitations)
}

type BulkCreateResponse struct {
type bulkCreateResponse struct {
clerk.APIResource
Invitations []*clerk.Invitation
}

func (b *BulkCreateResponse) UnmarshalJSON(data []byte) error {
func (b *bulkCreateResponse) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &b.Invitations)
}

// BulkCreate creates multiple invitations.
func (c *Client) BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.InvitationList, error) {
func (c *Client) BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.Invitations, error) {
req := clerk.NewAPIRequest(http.MethodPost, fmt.Sprintf("%s/bulk", path))
req.SetParams(params)

res := &BulkCreateResponse{}
res := &bulkCreateResponse{}
err := c.Backend.Call(ctx, req, res)
if err != nil {
return nil, err
}

return &clerk.InvitationList{
return &clerk.Invitations{
APIResource: res.APIResource,
Invitations: res.Invitations,
TotalCount: int64(len(res.Invitations)),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions invitation/invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func TestBulkInvitationCreate(t *testing.T) {
},
}

invitationList, err := BulkCreate(context.Background(), &params)
response, err := BulkCreate(context.Background(), &params)
require.NoError(t, err)
require.Equal(t, int64(len(invitations)), invitationList.TotalCount)
require.Len(t, invitations, 2)

for i, invitation := range invitationList.Invitations {
for i, invitation := range response.Invitations {
require.Equal(t, ids[i], invitation.ID)
require.Equal(t, emailAddresses[i], invitation.EmailAddress)
}
Expand Down

0 comments on commit 0d2d9a1

Please sign in to comment.