72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package tenant
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
domaintenant "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/tenant"
|
|
)
|
|
|
|
// GetTenantInput represents the input for getting a tenant
|
|
type GetTenantInput struct {
|
|
ID string
|
|
}
|
|
|
|
// GetTenantBySlugInput represents the input for getting a tenant by slug
|
|
type GetTenantBySlugInput struct {
|
|
Slug string
|
|
}
|
|
|
|
// GetTenantOutput represents the output after getting a tenant
|
|
type GetTenantOutput struct {
|
|
ID string
|
|
Name string
|
|
Slug string
|
|
Status string
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// GetTenantUseCase handles tenant retrieval business logic
|
|
type GetTenantUseCase struct {
|
|
repo domaintenant.Repository
|
|
}
|
|
|
|
// ProvideGetTenantUseCase creates a new GetTenantUseCase
|
|
func ProvideGetTenantUseCase(repo domaintenant.Repository) *GetTenantUseCase {
|
|
return &GetTenantUseCase{repo: repo}
|
|
}
|
|
|
|
// Execute retrieves a tenant by ID
|
|
func (uc *GetTenantUseCase) Execute(ctx context.Context, input *GetTenantInput) (*GetTenantOutput, error) {
|
|
tenant, err := uc.repo.GetByID(ctx, input.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &GetTenantOutput{
|
|
ID: tenant.ID,
|
|
Name: tenant.Name,
|
|
Slug: tenant.Slug,
|
|
Status: string(tenant.Status),
|
|
CreatedAt: tenant.CreatedAt,
|
|
UpdatedAt: tenant.UpdatedAt,
|
|
}, nil
|
|
}
|
|
|
|
// ExecuteBySlug retrieves a tenant by slug
|
|
func (uc *GetTenantUseCase) ExecuteBySlug(ctx context.Context, input *GetTenantBySlugInput) (*GetTenantOutput, error) {
|
|
tenant, err := uc.repo.GetBySlug(ctx, input.Slug)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &GetTenantOutput{
|
|
ID: tenant.ID,
|
|
Name: tenant.Name,
|
|
Slug: tenant.Slug,
|
|
Status: string(tenant.Status),
|
|
CreatedAt: tenant.CreatedAt,
|
|
UpdatedAt: tenant.UpdatedAt,
|
|
}, nil
|
|
}
|