Skip to content

Commit

Permalink
feat(CCO-361)!: add list teams
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Team is now renamed to PayingTeam. New Team added for non-paying related teams.
  • Loading branch information
CodingBoulderingRepeat committed Sep 11, 2023
1 parent 6940e6d commit bc5d5af
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 8 deletions.
2 changes: 1 addition & 1 deletion charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Charge struct {
Currency *Currency `json:"currency"`

// PayingTeam is the team paying for the charge.
PayingTeam *Team `json:"payingTeam"`
PayingTeam *PayingTeam `json:"payingTeam"`

// ChargeAuth is the method used to authenticate the charge.
ChargeAuth *ChargeAuth `json:"chargeAuth"`
Expand Down
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ type Client interface {
request *ListWalletTransactionsRequest,
) (*ListWalletTransactionsResponse, error)
GetWalletTransaction(ctx context.Context, transactionID int64) (*WalletTransaction, error)

// Teams
ListTeams(
ctx context.Context,
request *ListTeamsRequest,
) (*ListTeamsResponse, error)
}

// clientImpl to the Monta Partner API.
Expand Down
40 changes: 40 additions & 0 deletions client_teams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package monta

import (
"context"
"net/url"
)

// ListTeamsRequest is the request input to the [Client.ListTeams] method.
type ListTeamsRequest struct {
PageFilters
// Filter teams by partner external id. To filter only resources without PartnerExternalID use "".
PartnerExternalID *string
// If the team can be deleted.
IncludeDeleted bool
}

// ListTeamsResponse is the response output from the [Client.ListTeams] method.
type ListTeamsResponse struct {
// Teams in the current page.
Teams []*Team `json:"data"`
// PageMeta with metadata about the current page.
PageMeta PageMeta `json:"meta"`
}

// ListTeams to retrieve your teams.
func (c *clientImpl) ListTeams(
ctx context.Context,
request *ListTeamsRequest,
) (*ListTeamsResponse, error) {
path := "/v1/teams"
query := url.Values{}
request.PageFilters.Apply(query)
if request.PartnerExternalID != nil {
query.Set("partnerExternalId", *request.PartnerExternalID)
}
if request.IncludeDeleted {
query.Set("includeDeleted", "true")
}
return doGet[ListTeamsResponse](ctx, c, path, query)
}
13 changes: 13 additions & 0 deletions paying_team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package monta

// Team of Monta users.
type PayingTeam struct {
// ID of the team.
ID int64 `json:"id"`

// Public name of the team.
PublicName string `json:"publicName"`

// External Id of this entity, managed by you.
PartnerExternalID *string `json:"partnerExternalId"`
}
39 changes: 37 additions & 2 deletions team.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
package monta

import "time"

// Team of Monta users.
type Team struct {
// ID of the team.
ID int64 `json:"id"`

// Public name of the team.
PublicName string `json:"publicName"`
// Name of the team.
Name string `json:"name"`

// External Id of the team.
ExternalID *string `json:"externalId"`

// External Id of this entity, managed by you.
PartnerExternalID *string `json:"partnerExternalId"`

// Code to share with a user to join the team.
JoinCode string `json:"joinCode"`

// Company name for the given team.
CompanyName *string `json:"companyName"`

// Operator of the team.
Operator Operator `json:"operator"`

// Address of the team.
Address Address `json:"address"`

// Type of the team.
Type *string `json:"type"`

// Operator Id of the team.
OperatorID int64 `json:"operatorId"`

// When the team was blocked.
BlockedAt *time.Time `json:"blockedAt"`

// When the team was created.
CreatedAt time.Time `json:"createdAt"`

// When the team was last updated.
UpdatedAt time.Time `json:"updatedAt"`

// When the team was deleted.
DeletedAt *time.Time `json:"deletedAt"`
}
8 changes: 4 additions & 4 deletions wallettransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type WalletTransaction struct {
From json.RawMessage `json:"from"`

// FromTeam holds the parsed value of From when [FromType] is [TypeTeam].
FromTeam *Team `json:"-"`
FromTeam *PayingTeam `json:"-"`

// FromOperator holds the parsed value of From when [FromType] is [TypeOperator].
FromOperator *Operator `json:"-"`
Expand All @@ -44,7 +44,7 @@ type WalletTransaction struct {
ToOperator *Operator `json:"-"`

// ToTeam is used when [ToType] is "team".
ToTeam *Team `json:"-"`
ToTeam *PayingTeam `json:"-"`

// Exchange rate used for currency conversion.
ExchangeRate float64 `json:"exchangeRate"`
Expand Down Expand Up @@ -81,7 +81,7 @@ func (w *WalletTransaction) UnmarshalJSON(data []byte) error {
*w = WalletTransaction(t)
switch w.FromType {
case ToFromTypeTeam:
var fromTeam Team
var fromTeam PayingTeam
if err := json.Unmarshal(w.From, &fromTeam); err != nil {
return err
}
Expand All @@ -95,7 +95,7 @@ func (w *WalletTransaction) UnmarshalJSON(data []byte) error {
}
switch w.ToType {
case ToFromTypeTeam:
var toTeam Team
var toTeam PayingTeam
if err := json.Unmarshal(w.To, &toTeam); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion wallettransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestWalletTransaction_MarshalJSON(t *testing.T) {
`)
var walletTransaction WalletTransaction
assert.NilError(t, json.Unmarshal([]byte(expected), &walletTransaction))
expectedFromTeam := &Team{
expectedFromTeam := &PayingTeam{
ID: 14,
PublicName: "Monta",
PartnerExternalID: toPointer("abcd"),
Expand Down

0 comments on commit bc5d5af

Please sign in to comment.