tenants

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTenantNotFound = errors.New("tenant not found")
	ErrTenantExists   = errors.New("tenant already exists")
)

Errors

Functions

func RegisterRoutes

func RegisterRoutes(router *gin.RouterGroup, deps *app.RuntimeDeps)

RegisterRoutes registers tenant routes.

Types

type CreateTenantRequest

type CreateTenantRequest struct {
	Name   string `json:"name" validate:"required"`
	Slug   string `json:"slug" validate:"required,slug"`
	Status string `json:"status,omitempty"`
}

CreateTenantRequest represents the request to create a tenant.

type Repository

type Repository interface {
	Create(ctx context.Context, t *Tenant) error
	GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)
	GetBySlug(ctx context.Context, slug string) (*Tenant, error)
	Update(ctx context.Context, t *Tenant) error
}

Repository defines the contract for tenant persistence.

func NewTenantRepositoryPostgres

func NewTenantRepositoryPostgres(db *database.Postgres) Repository

NewTenantRepositoryPostgres creates a new PostgreSQL tenant repository.

type Service

type Service interface {
	CreateTenant(ctx context.Context, req *CreateTenantRequest) (*TenantResponse, error)
	GetTenantByID(ctx context.Context, id uuid.UUID) (*TenantResponse, error)
	GetTenantBySlug(ctx context.Context, slug string) (*TenantResponse, error)
	UpdateTenant(ctx context.Context, id uuid.UUID, req *UpdateTenantRequest) (*TenantResponse, error)
}

Service defines the contract for tenant business logic.

type Tenant

type Tenant struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	Status    string    `json:"status"`
	Settings  []byte    `json:"settings,omitempty"` // JSONB stored as []byte
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Tenant represents a tenant in the system.

type TenantHandler

type TenantHandler struct {
	// contains filtered or unexported fields
}

TenantHandler handles HTTP requests for tenants.

func NewTenantHandler

func NewTenantHandler(service *TenantService, logger *logger.Logger) *TenantHandler

NewTenantHandler creates a new tenant handler.

func (*TenantHandler) CreateTenant

func (h *TenantHandler) CreateTenant(c *gin.Context)

CreateTenant handles POST /tenants

func (*TenantHandler) GetTenant

func (h *TenantHandler) GetTenant(c *gin.Context)

GetTenant handles GET /tenants/:id

func (*TenantHandler) UpdateTenant

func (h *TenantHandler) UpdateTenant(c *gin.Context)

UpdateTenant handles PUT /tenants/:id

type TenantRepositoryPostgres

type TenantRepositoryPostgres struct {
	// contains filtered or unexported fields
}

TenantRepositoryPostgres implements Repository using PostgreSQL.

func (*TenantRepositoryPostgres) Create

Create inserts a new tenant into the database.

func (*TenantRepositoryPostgres) GetByID

func (r *TenantRepositoryPostgres) GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)

GetByID retrieves a tenant by its ID.

func (*TenantRepositoryPostgres) GetBySlug

func (r *TenantRepositoryPostgres) GetBySlug(ctx context.Context, slug string) (*Tenant, error)

GetBySlug retrieves a tenant by its slug.

func (*TenantRepositoryPostgres) Update

Update updates an existing tenant.

type TenantResponse

type TenantResponse struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Slug      string `json:"slug"`
	Status    string `json:"status"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

TenantResponse represents the response for tenant operations.

type TenantService

type TenantService struct {
	// contains filtered or unexported fields
}

TenantService provides tenant business logic.

func NewTenantService

func NewTenantService(repo Repository, logger *logger.Logger) *TenantService

NewTenantService creates a new tenant service.

func (*TenantService) CreateTenant

func (s *TenantService) CreateTenant(ctx context.Context, req *CreateTenantRequest) (*TenantResponse, error)

CreateTenant creates a new tenant.

func (*TenantService) GetTenantByID

func (s *TenantService) GetTenantByID(ctx context.Context, id uuid.UUID) (*TenantResponse, error)

GetTenantByID returns a tenant by ID.

func (*TenantService) GetTenantBySlug

func (s *TenantService) GetTenantBySlug(ctx context.Context, slug string) (*TenantResponse, error)

GetTenantBySlug returns a tenant by slug.

func (*TenantService) UpdateTenant

func (s *TenantService) UpdateTenant(ctx context.Context, id uuid.UUID, req *UpdateTenantRequest) (*TenantResponse, error)

UpdateTenant updates a tenant.

type UpdateTenantRequest

type UpdateTenantRequest struct {
	Name   string `json:"name,omitempty"`
	Slug   string `json:"slug,omitempty,slug"`
	Status string `json:"status,omitempty"`
}

UpdateTenantRequest represents the request to update a tenant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL