go-forge/orgs.go
Snider 0a9564274d
All checks were successful
Security Scan / security (pull_request) Successful in 9s
Test / test (pull_request) Successful in 1m20s
refactor(module): migrate module path to dappco.re/go/core/forge
Update Go module path from forge.lthn.ai/core/go-forge to
dappco.re/go/core/forge. Migrate all import paths and dependency
references (go-io → dappco.re/go/core/io, go-log → dappco.re/go/core/log).
Update documentation (CLAUDE.md, README.md, docs/) to reflect new paths.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 01:51:29 +00:00

68 lines
2.5 KiB
Go

package forge
import (
"context"
"fmt"
"iter"
"dappco.re/go/core/forge/types"
)
// OrgService handles organisation operations.
type OrgService struct {
Resource[types.Organization, types.CreateOrgOption, types.EditOrgOption]
}
func newOrgService(c *Client) *OrgService {
return &OrgService{
Resource: *NewResource[types.Organization, types.CreateOrgOption, types.EditOrgOption](
c, "/api/v1/orgs/{org}",
),
}
}
// ListMembers returns all members of an organisation.
func (s *OrgService) ListMembers(ctx context.Context, org string) ([]types.User, error) {
path := fmt.Sprintf("/api/v1/orgs/%s/members", org)
return ListAll[types.User](ctx, s.client, path, nil)
}
// IterMembers returns an iterator over all members of an organisation.
func (s *OrgService) IterMembers(ctx context.Context, org string) iter.Seq2[types.User, error] {
path := fmt.Sprintf("/api/v1/orgs/%s/members", org)
return ListIter[types.User](ctx, s.client, path, nil)
}
// AddMember adds a user to an organisation.
func (s *OrgService) AddMember(ctx context.Context, org, username string) error {
path := fmt.Sprintf("/api/v1/orgs/%s/members/%s", org, username)
return s.client.Put(ctx, path, nil, nil)
}
// RemoveMember removes a user from an organisation.
func (s *OrgService) RemoveMember(ctx context.Context, org, username string) error {
path := fmt.Sprintf("/api/v1/orgs/%s/members/%s", org, username)
return s.client.Delete(ctx, path)
}
// ListUserOrgs returns all organisations for a user.
func (s *OrgService) ListUserOrgs(ctx context.Context, username string) ([]types.Organization, error) {
path := fmt.Sprintf("/api/v1/users/%s/orgs", username)
return ListAll[types.Organization](ctx, s.client, path, nil)
}
// IterUserOrgs returns an iterator over all organisations for a user.
func (s *OrgService) IterUserOrgs(ctx context.Context, username string) iter.Seq2[types.Organization, error] {
path := fmt.Sprintf("/api/v1/users/%s/orgs", username)
return ListIter[types.Organization](ctx, s.client, path, nil)
}
// ListMyOrgs returns all organisations for the authenticated user.
func (s *OrgService) ListMyOrgs(ctx context.Context) ([]types.Organization, error) {
return ListAll[types.Organization](ctx, s.client, "/api/v1/user/orgs", nil)
}
// IterMyOrgs returns an iterator over all organisations for the authenticated user.
func (s *OrgService) IterMyOrgs(ctx context.Context) iter.Seq2[types.Organization, error] {
return ListIter[types.Organization](ctx, s.client, "/api/v1/user/orgs", nil)
}