Documentation
¶
Overview ¶
Package tenant provides multi-tenant functionality.
Index ¶
- Variables
- func GetTenantIDFromContext(ctx context.Context) uuid.UUID
- func GetTenantIDFromEchoContext(c echo.Context) uuid.UUID
- type AcceptInvitationRequest
- type ContextKey
- type CreateTenantRequest
- type Handler
- func (h *Handler) AcceptInvitation(c echo.Context) error
- func (h *Handler) CancelInvitation(c echo.Context) error
- func (h *Handler) CreateTenant(c echo.Context) error
- func (h *Handler) DeleteTenant(c echo.Context) error
- func (h *Handler) GetLimits(c echo.Context) error
- func (h *Handler) GetSettings(c echo.Context) error
- func (h *Handler) GetTenant(c echo.Context) error
- func (h *Handler) InviteMember(c echo.Context) error
- func (h *Handler) ListInvitations(c echo.Context) error
- func (h *Handler) ListMembers(c echo.Context) error
- func (h *Handler) ListTenants(c echo.Context) error
- func (h *Handler) RegisterRoutes(g *echo.Group)
- func (h *Handler) RemoveMember(c echo.Context) error
- func (h *Handler) TransferOwnership(c echo.Context) error
- func (h *Handler) UpdateLimits(c echo.Context) error
- func (h *Handler) UpdateMember(c echo.Context) error
- func (h *Handler) UpdateSettings(c echo.Context) error
- func (h *Handler) UpdateTenant(c echo.Context) error
- type InviteMemberRequest
- type ListMembersQuery
- type ListMembersResponse
- type ListTenantsQuery
- type ListTenantsResponse
- type MemberRole
- type Middleware
- type Repository
- type SQLiteRepository
- func (r *SQLiteRepository) AcceptInvitation(ctx context.Context, id uuid.UUID) error
- func (r *SQLiteRepository) AddMember(ctx context.Context, member *TenantMember) error
- func (r *SQLiteRepository) CleanupExpiredInvitations(ctx context.Context) error
- func (r *SQLiteRepository) CountMembers(ctx context.Context, tenantID uuid.UUID) (int64, error)
- func (r *SQLiteRepository) Create(ctx context.Context, tenant *Tenant) error
- func (r *SQLiteRepository) CreateInvitation(ctx context.Context, invitation *TenantInvitation) error
- func (r *SQLiteRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *SQLiteRepository) DeleteInvitation(ctx context.Context, id uuid.UUID) error
- func (r *SQLiteRepository) ExistsBySlug(ctx context.Context, slug string) (bool, error)
- func (r *SQLiteRepository) GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)
- func (r *SQLiteRepository) GetBySlug(ctx context.Context, slug string) (*Tenant, error)
- func (r *SQLiteRepository) GetInvitationByID(ctx context.Context, id uuid.UUID) (*TenantInvitation, error)
- func (r *SQLiteRepository) GetInvitationByToken(ctx context.Context, token string) (*TenantInvitation, error)
- func (r *SQLiteRepository) GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)
- func (r *SQLiteRepository) GetPendingInvitationByEmail(ctx context.Context, tenantID uuid.UUID, email string) (*TenantInvitation, error)
- func (r *SQLiteRepository) GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)
- func (r *SQLiteRepository) InitSchema(ctx context.Context) error
- func (r *SQLiteRepository) IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)
- func (r *SQLiteRepository) List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
- func (r *SQLiteRepository) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
- func (r *SQLiteRepository) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
- func (r *SQLiteRepository) RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error
- func (r *SQLiteRepository) Update(ctx context.Context, tenant *Tenant) error
- func (r *SQLiteRepository) UpdateMember(ctx context.Context, member *TenantMember) error
- type Service
- func (s *Service) AcceptInvitation(ctx context.Context, token string, userID uuid.UUID) (*Tenant, error)
- func (s *Service) CancelInvitation(ctx context.Context, invitationID uuid.UUID) error
- func (s *Service) CleanupExpiredInvitations(ctx context.Context) error
- func (s *Service) Create(ctx context.Context, req *CreateTenantRequest, ownerID uuid.UUID) (*Tenant, error)
- func (s *Service) Delete(ctx context.Context, id uuid.UUID) error
- func (s *Service) GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)
- func (s *Service) GetBySlug(ctx context.Context, slug string) (*Tenant, error)
- func (s *Service) GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)
- func (s *Service) GetTenantLimits(ctx context.Context, tenantID uuid.UUID) (*TenantLimits, error)
- func (s *Service) GetTenantSettings(ctx context.Context, tenantID uuid.UUID) (*TenantSettings, error)
- func (s *Service) GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)
- func (s *Service) HasPermission(ctx context.Context, tenantID, userID uuid.UUID, requiredRole MemberRole) (bool, error)
- func (s *Service) InviteMember(ctx context.Context, tenantID uuid.UUID, req *InviteMemberRequest, ...) (*TenantInvitation, error)
- func (s *Service) IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)
- func (s *Service) List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
- func (s *Service) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
- func (s *Service) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
- func (s *Service) RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error
- func (s *Service) TransferOwnership(ctx context.Context, tenantID, currentOwnerID, newOwnerID uuid.UUID) error
- func (s *Service) Update(ctx context.Context, id uuid.UUID, req *UpdateTenantRequest) (*Tenant, error)
- func (s *Service) UpdateMemberRole(ctx context.Context, tenantID, userID uuid.UUID, role MemberRole) error
- func (s *Service) UpdateTenantLimits(ctx context.Context, tenantID uuid.UUID, limits *TenantLimits) error
- func (s *Service) UpdateTenantSettings(ctx context.Context, tenantID uuid.UUID, settings *TenantSettings) error
- type ServiceConfig
- type Status
- type Tenant
- type TenantInvitation
- type TenantLimits
- type TenantMember
- type TenantMemberWithUser
- type TenantSettings
- type TransferOwnershipRequest
- type UpdateMemberRequest
- type UpdateTenantRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTenantNotFound is returned when a tenant is not found. ErrTenantNotFound = errors.New("tenant not found") // ErrTenantExists is returned when a tenant already exists. ErrTenantExists = errors.New("tenant already exists") // ErrSlugExists is returned when a slug is already taken. ErrSlugExists = errors.New("slug already exists") // ErrMemberNotFound is returned when a member is not found. ErrMemberNotFound = errors.New("member not found") // ErrMemberExists is returned when a member already exists. ErrMemberExists = errors.New("member already exists in tenant") // ErrInvitationNotFound is returned when an invitation is not found. ErrInvitationNotFound = errors.New("invitation not found") // ErrInvitationExpired is returned when an invitation has expired. ErrInvitationExpired = errors.New("invitation expired") // ErrInvitationAlreadyAccepted is returned when an invitation was already accepted. ErrInvitationAlreadyAccepted = errors.New("invitation already accepted") // ErrCannotRemoveOwner is returned when trying to remove the tenant owner. ErrCannotRemoveOwner = errors.New("cannot remove tenant owner") // ErrCannotChangeOwnerRole is returned when trying to change owner's role. ErrCannotChangeOwnerRole = errors.New("cannot change owner role") // ErrLimitExceeded is returned when a tenant limit is exceeded. ErrLimitExceeded = errors.New("tenant limit exceeded") )
Functions ¶
func GetTenantIDFromContext ¶
GetTenantIDFromContext retrieves the tenant ID from context.
Types ¶
type AcceptInvitationRequest ¶
type AcceptInvitationRequest struct {
Token string `json:"token" validate:"required"`
}
AcceptInvitationRequest represents a request to accept an invitation.
type ContextKey ¶
type ContextKey string
ContextKey is the type for context keys.
const ( // TenantIDKey is the context key for tenant ID. TenantIDKey ContextKey = "tenant_id" // TenantKey is the context key for tenant object. TenantKey ContextKey = "tenant" // MemberKey is the context key for member object. MemberKey ContextKey = "tenant_member" )
type CreateTenantRequest ¶
type CreateTenantRequest struct {
Name string `json:"name" validate:"required,min=2,max=100"`
Slug string `json:"slug" validate:"required,min=2,max=50,alphanum"`
Description *string `json:"description,omitempty" validate:"omitempty,max=500"`
}
CreateTenantRequest represents a request to create a tenant.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for tenant management.
func NewHandler ¶
NewHandler creates a new tenant handler.
func (*Handler) AcceptInvitation ¶
AcceptInvitation handles accepting an invitation.
func (*Handler) CancelInvitation ¶
CancelInvitation handles canceling an invitation.
func (*Handler) CreateTenant ¶
CreateTenant handles tenant creation.
func (*Handler) DeleteTenant ¶
DeleteTenant handles deleting a tenant.
func (*Handler) GetSettings ¶
GetSettings handles getting tenant settings.
func (*Handler) InviteMember ¶
InviteMember handles inviting a new member.
func (*Handler) ListInvitations ¶
ListInvitations handles listing pending invitations.
func (*Handler) ListMembers ¶
ListMembers handles listing members of a tenant.
func (*Handler) ListTenants ¶
ListTenants handles listing tenants for the current user.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers the tenant routes.
func (*Handler) RemoveMember ¶
RemoveMember handles removing a member from a tenant.
func (*Handler) TransferOwnership ¶
TransferOwnership handles transferring tenant ownership.
func (*Handler) UpdateLimits ¶
UpdateLimits handles updating tenant limits (admin only).
func (*Handler) UpdateMember ¶
UpdateMember handles updating a member's role.
func (*Handler) UpdateSettings ¶
UpdateSettings handles updating tenant settings.
type InviteMemberRequest ¶
type InviteMemberRequest struct {
Email string `json:"email" validate:"required,email"`
Role MemberRole `json:"role" validate:"required,oneof=admin member"`
}
InviteMemberRequest represents a request to invite a member.
type ListMembersQuery ¶
type ListMembersQuery struct {
Page int `query:"page"`
PageSize int `query:"page_size"`
Role *MemberRole `query:"role"`
}
ListMembersQuery represents query parameters for listing members.
type ListMembersResponse ¶
type ListMembersResponse struct {
Members []*TenantMemberWithUser `json:"members"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
}
ListMembersResponse represents a paginated list of members.
type ListTenantsQuery ¶
type ListTenantsQuery struct {
Page int `query:"page"`
PageSize int `query:"page_size"`
Search string `query:"search"`
Status *Status `query:"status"`
SortBy string `query:"sort_by"`
SortDir string `query:"sort_dir"`
}
ListTenantsQuery represents query parameters for listing tenants.
type ListTenantsResponse ¶
type ListTenantsResponse struct {
Tenants []*Tenant `json:"tenants"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
}
ListTenantsResponse represents a paginated list of tenants.
type MemberRole ¶
type MemberRole string
MemberRole represents a user's role within a tenant.
const ( // MemberRoleOwner has full control over the tenant. MemberRoleOwner MemberRole = "owner" // MemberRoleAdmin can manage tenant settings and members. MemberRoleAdmin MemberRole = "admin" // MemberRoleMember has standard access. MemberRoleMember MemberRole = "member" )
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware provides tenant-related middleware.
func NewMiddleware ¶
func NewMiddleware(service *Service) *Middleware
NewMiddleware creates a new tenant middleware.
func (*Middleware) OptionalTenant ¶
func (m *Middleware) OptionalTenant() echo.MiddlewareFunc
OptionalTenant middleware sets tenant context if provided, but doesn't require it.
func (*Middleware) RequireRole ¶
func (m *Middleware) RequireRole(requiredRole MemberRole) echo.MiddlewareFunc
RequireRole middleware ensures the user has at least the specified role in the tenant. Must be used after RequireTenant middleware.
func (*Middleware) RequireTenant ¶
func (m *Middleware) RequireTenant() echo.MiddlewareFunc
RequireTenant middleware ensures a tenant is selected and the user is a member. It expects the tenant ID to be in the X-Tenant-ID header or tenant_id query parameter.
type Repository ¶
type Repository interface {
// Tenant operations
// Create creates a new tenant.
Create(ctx context.Context, tenant *Tenant) error
// GetByID retrieves a tenant by ID.
GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)
// GetBySlug retrieves a tenant by slug.
GetBySlug(ctx context.Context, slug string) (*Tenant, error)
// Update updates a tenant.
Update(ctx context.Context, tenant *Tenant) error
// Delete soft-deletes a tenant.
Delete(ctx context.Context, id uuid.UUID) error
// List retrieves tenants with pagination and filtering.
List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
// ExistsBySlug checks if a slug exists.
ExistsBySlug(ctx context.Context, slug string) (bool, error)
// GetUserTenants retrieves all tenants a user belongs to.
GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)
// Member operations
// AddMember adds a member to a tenant.
AddMember(ctx context.Context, member *TenantMember) error
// GetMember retrieves a member by tenant and user ID.
GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)
// UpdateMember updates a member's role.
UpdateMember(ctx context.Context, member *TenantMember) error
// RemoveMember removes a member from a tenant.
RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error
// ListMembers retrieves members of a tenant with pagination.
ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
// CountMembers returns the number of members in a tenant.
CountMembers(ctx context.Context, tenantID uuid.UUID) (int64, error)
// IsMember checks if a user is a member of a tenant.
IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)
// Invitation operations
// CreateInvitation creates a new invitation.
CreateInvitation(ctx context.Context, invitation *TenantInvitation) error
// GetInvitationByID retrieves an invitation by ID.
GetInvitationByID(ctx context.Context, id uuid.UUID) (*TenantInvitation, error)
// GetInvitationByToken retrieves an invitation by token.
GetInvitationByToken(ctx context.Context, token string) (*TenantInvitation, error)
// GetPendingInvitationByEmail retrieves a pending invitation by email for a tenant.
GetPendingInvitationByEmail(ctx context.Context, tenantID uuid.UUID, email string) (*TenantInvitation, error)
// AcceptInvitation marks an invitation as accepted.
AcceptInvitation(ctx context.Context, id uuid.UUID) error
// DeleteInvitation deletes an invitation.
DeleteInvitation(ctx context.Context, id uuid.UUID) error
// ListPendingInvitations retrieves pending invitations for a tenant.
ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
// CleanupExpiredInvitations removes expired invitations.
CleanupExpiredInvitations(ctx context.Context) error
}
Repository defines the interface for tenant data access.
type SQLiteRepository ¶
type SQLiteRepository struct {
// contains filtered or unexported fields
}
SQLiteRepository implements Repository using SQLite.
func NewSQLiteRepository ¶
func NewSQLiteRepository(db *sql.DB) *SQLiteRepository
NewSQLiteRepository creates a new SQLiteRepository.
func NewSQLiteRepositoryWithReadDB ¶
func NewSQLiteRepositoryWithReadDB(writeDB, readDB *sql.DB) *SQLiteRepository
NewSQLiteRepositoryWithReadDB creates a new SQLiteRepository with separate write and read database handles.
func (*SQLiteRepository) AcceptInvitation ¶
AcceptInvitation marks an invitation as accepted.
func (*SQLiteRepository) AddMember ¶
func (r *SQLiteRepository) AddMember(ctx context.Context, member *TenantMember) error
AddMember adds a member to a tenant.
func (*SQLiteRepository) CleanupExpiredInvitations ¶
func (r *SQLiteRepository) CleanupExpiredInvitations(ctx context.Context) error
CleanupExpiredInvitations removes expired invitations.
func (*SQLiteRepository) CountMembers ¶
CountMembers returns the number of members in a tenant.
func (*SQLiteRepository) Create ¶
func (r *SQLiteRepository) Create(ctx context.Context, tenant *Tenant) error
Create creates a new tenant.
func (*SQLiteRepository) CreateInvitation ¶
func (r *SQLiteRepository) CreateInvitation(ctx context.Context, invitation *TenantInvitation) error
CreateInvitation creates a new invitation.
func (*SQLiteRepository) DeleteInvitation ¶
DeleteInvitation deletes an invitation.
func (*SQLiteRepository) ExistsBySlug ¶
ExistsBySlug checks if a slug exists.
func (*SQLiteRepository) GetInvitationByID ¶
func (r *SQLiteRepository) GetInvitationByID(ctx context.Context, id uuid.UUID) (*TenantInvitation, error)
GetInvitationByID retrieves an invitation by ID.
func (*SQLiteRepository) GetInvitationByToken ¶
func (r *SQLiteRepository) GetInvitationByToken(ctx context.Context, token string) (*TenantInvitation, error)
GetInvitationByToken retrieves an invitation by token.
func (*SQLiteRepository) GetMember ¶
func (r *SQLiteRepository) GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)
GetMember retrieves a member by tenant and user ID.
func (*SQLiteRepository) GetPendingInvitationByEmail ¶
func (r *SQLiteRepository) GetPendingInvitationByEmail(ctx context.Context, tenantID uuid.UUID, email string) (*TenantInvitation, error)
GetPendingInvitationByEmail retrieves a pending invitation by email for a tenant.
func (*SQLiteRepository) GetUserTenants ¶
GetUserTenants retrieves all tenants a user belongs to.
func (*SQLiteRepository) InitSchema ¶
func (r *SQLiteRepository) InitSchema(ctx context.Context) error
InitSchema creates the necessary tables.
func (*SQLiteRepository) List ¶
func (r *SQLiteRepository) List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
List retrieves tenants with pagination and filtering.
func (*SQLiteRepository) ListMembers ¶
func (r *SQLiteRepository) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
ListMembers retrieves members of a tenant with pagination.
func (*SQLiteRepository) ListPendingInvitations ¶
func (r *SQLiteRepository) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
ListPendingInvitations retrieves pending invitations for a tenant.
func (*SQLiteRepository) RemoveMember ¶
RemoveMember removes a member from a tenant.
func (*SQLiteRepository) Update ¶
func (r *SQLiteRepository) Update(ctx context.Context, tenant *Tenant) error
Update updates a tenant.
func (*SQLiteRepository) UpdateMember ¶
func (r *SQLiteRepository) UpdateMember(ctx context.Context, member *TenantMember) error
UpdateMember updates a member's role.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides tenant management operations.
func NewService ¶
func NewService(repo Repository, config *ServiceConfig) *Service
NewService creates a new tenant service.
func (*Service) AcceptInvitation ¶
func (s *Service) AcceptInvitation(ctx context.Context, token string, userID uuid.UUID) (*Tenant, error)
AcceptInvitation accepts an invitation and adds the user to the tenant.
func (*Service) CancelInvitation ¶
CancelInvitation cancels a pending invitation.
func (*Service) CleanupExpiredInvitations ¶
CleanupExpiredInvitations removes expired invitations.
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, req *CreateTenantRequest, ownerID uuid.UUID) (*Tenant, error)
Create creates a new tenant and adds the creator as owner.
func (*Service) GetTenantLimits ¶
GetTenantLimits retrieves the limits for a tenant.
func (*Service) GetTenantSettings ¶
func (s *Service) GetTenantSettings(ctx context.Context, tenantID uuid.UUID) (*TenantSettings, error)
GetTenantSettings retrieves the settings for a tenant.
func (*Service) GetUserTenants ¶
GetUserTenants retrieves all tenants a user belongs to.
func (*Service) HasPermission ¶
func (s *Service) HasPermission(ctx context.Context, tenantID, userID uuid.UUID, requiredRole MemberRole) (bool, error)
HasPermission checks if a user has a specific role or higher in a tenant.
func (*Service) InviteMember ¶
func (s *Service) InviteMember(ctx context.Context, tenantID uuid.UUID, req *InviteMemberRequest, invitedBy uuid.UUID) (*TenantInvitation, error)
InviteMember creates an invitation to join a tenant.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
List retrieves tenants with pagination and filtering.
func (*Service) ListMembers ¶
func (s *Service) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
ListMembers retrieves members of a tenant with pagination.
func (*Service) ListPendingInvitations ¶
func (s *Service) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
ListPendingInvitations retrieves pending invitations for a tenant.
func (*Service) RemoveMember ¶
RemoveMember removes a member from a tenant.
func (*Service) TransferOwnership ¶
func (s *Service) TransferOwnership(ctx context.Context, tenantID, currentOwnerID, newOwnerID uuid.UUID) error
TransferOwnership transfers tenant ownership to another member.
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, id uuid.UUID, req *UpdateTenantRequest) (*Tenant, error)
Update updates a tenant.
func (*Service) UpdateMemberRole ¶
func (s *Service) UpdateMemberRole(ctx context.Context, tenantID, userID uuid.UUID, role MemberRole) error
UpdateMemberRole updates a member's role.
func (*Service) UpdateTenantLimits ¶
func (s *Service) UpdateTenantLimits(ctx context.Context, tenantID uuid.UUID, limits *TenantLimits) error
UpdateTenantLimits updates the limits for a tenant.
func (*Service) UpdateTenantSettings ¶
func (s *Service) UpdateTenantSettings(ctx context.Context, tenantID uuid.UUID, settings *TenantSettings) error
UpdateTenantSettings updates the settings for a tenant.
type ServiceConfig ¶
type ServiceConfig struct {
InvitationExpiry time.Duration
DefaultLimits *TenantLimits
DefaultSettings *TenantSettings
}
ServiceConfig contains configuration for the tenant service.
func DefaultServiceConfig ¶
func DefaultServiceConfig() *ServiceConfig
DefaultServiceConfig returns the default service configuration.
type Tenant ¶
type Tenant struct {
// ID is the unique identifier.
ID uuid.UUID `json:"id" db:"id"`
// Name is the tenant display name.
Name string `json:"name" db:"name"`
// Slug is the URL-friendly identifier.
Slug string `json:"slug" db:"slug"`
// Description is an optional description.
Description *string `json:"description,omitempty" db:"description"`
// Status is the tenant status.
Status Status `json:"status" db:"status"`
// Settings contains tenant-specific settings as JSON.
Settings *string `json:"settings,omitempty" db:"settings"`
// Limits contains resource limits as JSON.
Limits *string `json:"limits,omitempty" db:"limits"`
// OwnerID is the ID of the tenant owner.
OwnerID uuid.UUID `json:"owner_id" db:"owner_id"`
// CreatedAt is when the tenant was created.
CreatedAt time.Time `json:"created_at" db:"created_at"`
// UpdatedAt is when the tenant was last updated.
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
// DeletedAt is when the tenant was soft-deleted.
DeletedAt *time.Time `json:"-" db:"deleted_at"`
}
Tenant represents a tenant (organization) in the system.
func GetTenantFromContext ¶
GetTenantFromContext retrieves the tenant from context.
func GetTenantFromEchoContext ¶
GetTenantFromEchoContext retrieves the tenant from Echo context.
type TenantInvitation ¶
type TenantInvitation struct {
// ID is the unique identifier.
ID uuid.UUID `json:"id" db:"id"`
// TenantID is the tenant ID.
TenantID uuid.UUID `json:"tenant_id" db:"tenant_id"`
// Email is the invited email address.
Email string `json:"email" db:"email"`
// Role is the role to assign upon acceptance.
Role MemberRole `json:"role" db:"role"`
// Token is the invitation token.
Token string `json:"-" db:"token"`
// InvitedBy is the ID of the user who created the invitation.
InvitedBy uuid.UUID `json:"invited_by" db:"invited_by"`
// ExpiresAt is when the invitation expires.
ExpiresAt time.Time `json:"expires_at" db:"expires_at"`
// AcceptedAt is when the invitation was accepted.
AcceptedAt *time.Time `json:"accepted_at,omitempty" db:"accepted_at"`
// CreatedAt is when the invitation was created.
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
TenantInvitation represents an invitation to join a tenant.
func NewTenantInvitation ¶
func NewTenantInvitation(tenantID uuid.UUID, email string, role MemberRole, invitedBy uuid.UUID, token string, expiresAt time.Time) *TenantInvitation
NewTenantInvitation creates a new TenantInvitation.
func (*TenantInvitation) IsValid ¶
func (i *TenantInvitation) IsValid() bool
IsValid returns true if the invitation is not expired and not accepted.
type TenantLimits ¶
type TenantLimits struct {
// MaxUsers is the maximum number of users.
MaxUsers int `json:"max_users"`
// MaxStorage is the maximum storage in bytes.
MaxStorage int64 `json:"max_storage"`
// MaxAPIRequests is the maximum API requests per day.
MaxAPIRequests int `json:"max_api_requests"`
// MaxWorkflows is the maximum number of workflows.
MaxWorkflows int `json:"max_workflows"`
// MaxChannels is the maximum number of channels.
MaxChannels int `json:"max_channels"`
}
TenantLimits represents resource limits for a tenant.
func DefaultTenantLimits ¶
func DefaultTenantLimits() *TenantLimits
DefaultTenantLimits returns the default limits for a new tenant.
type TenantMember ¶
type TenantMember struct {
// ID is the unique identifier.
ID uuid.UUID `json:"id" db:"id"`
// TenantID is the tenant ID.
TenantID uuid.UUID `json:"tenant_id" db:"tenant_id"`
// UserID is the user ID.
UserID uuid.UUID `json:"user_id" db:"user_id"`
// Role is the member's role within the tenant.
Role MemberRole `json:"role" db:"role"`
// JoinedAt is when the user joined the tenant.
JoinedAt time.Time `json:"joined_at" db:"joined_at"`
// InvitedBy is the ID of the user who invited this member.
InvitedBy *uuid.UUID `json:"invited_by,omitempty" db:"invited_by"`
}
TenantMember represents a user's membership in a tenant.
func GetMemberFromContext ¶
func GetMemberFromContext(ctx context.Context) *TenantMember
GetMemberFromContext retrieves the member from context.
func GetMemberFromEchoContext ¶
func GetMemberFromEchoContext(c echo.Context) *TenantMember
GetMemberFromEchoContext retrieves the member from Echo context.
func NewTenantMember ¶
func NewTenantMember(tenantID, userID uuid.UUID, role MemberRole, invitedBy *uuid.UUID) *TenantMember
NewTenantMember creates a new TenantMember.
type TenantMemberWithUser ¶
type TenantMemberWithUser struct {
TenantMember
Username string `json:"username"`
Email *string `json:"email,omitempty"`
}
TenantMemberWithUser represents a member with user details.
type TenantSettings ¶
type TenantSettings struct {
// DefaultLanguage is the default language for the tenant.
DefaultLanguage string `json:"default_language"`
// Timezone is the default timezone.
Timezone string `json:"timezone"`
// Features contains enabled feature flags.
Features map[string]bool `json:"features"`
}
TenantSettings represents tenant-specific settings.
func DefaultTenantSettings ¶
func DefaultTenantSettings() *TenantSettings
DefaultTenantSettings returns the default settings for a new tenant.
type TransferOwnershipRequest ¶
type TransferOwnershipRequest struct {
NewOwnerID uuid.UUID `json:"new_owner_id" validate:"required"`
}
TransferOwnershipRequest represents a request to transfer ownership.
type UpdateMemberRequest ¶
type UpdateMemberRequest struct {
Role MemberRole `json:"role" validate:"required,oneof=owner admin member"`
}
UpdateMemberRequest represents a request to update a member's role.
type UpdateTenantRequest ¶
type UpdateTenantRequest struct {
Name *string `json:"name,omitempty" validate:"omitempty,min=2,max=100"`
Description *string `json:"description,omitempty" validate:"omitempty,max=500"`
Status *Status `json:"status,omitempty"`
}
UpdateTenantRequest represents a request to update a tenant.