diff --git a/charge.go b/charge.go index b84d5c9..bc01b3c 100644 --- a/charge.go +++ b/charge.go @@ -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"` diff --git a/client.go b/client.go index d34260a..b4a2e27 100644 --- a/client.go +++ b/client.go @@ -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. diff --git a/client_teams.go b/client_teams.go new file mode 100644 index 0000000..b488625 --- /dev/null +++ b/client_teams.go @@ -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) +} diff --git a/paying_team.go b/paying_team.go new file mode 100644 index 0000000..168c772 --- /dev/null +++ b/paying_team.go @@ -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"` +} diff --git a/team.go b/team.go index 117214a..9e4599f 100644 --- a/team.go +++ b/team.go @@ -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"` } diff --git a/wallettransaction.go b/wallettransaction.go index 5c9bfe0..f715736 100644 --- a/wallettransaction.go +++ b/wallettransaction.go @@ -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:"-"` @@ -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"` @@ -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 } @@ -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 } diff --git a/wallettransaction_test.go b/wallettransaction_test.go index f35ae4a..45f661e 100644 --- a/wallettransaction_test.go +++ b/wallettransaction_test.go @@ -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"),