Documentation
¶
Overview ¶
Package preview provides preview mode functionality for ZimaOS-Blue. Preview mode allows users to experience the product without creating an account.
Index ¶
- Variables
- type Handler
- func (h *Handler) GetOnboardingStatus(c echo.Context) error
- func (h *Handler) GetPresetQuestions(c echo.Context) error
- func (h *Handler) GetPreviewStatus(c echo.Context) error
- func (h *Handler) GetPreviewToken(c echo.Context) error
- func (h *Handler) GetSystemMode(c echo.Context) error
- func (h *Handler) RegisterRoutes(e *echo.Echo)
- func (h *Handler) SetDataDir(dataDir string)
- func (h *Handler) SetOnboardingSeen(c echo.Context) error
- func (h *Handler) Upgrade(c echo.Context) error
- type MigrationResult
- type MigrationService
- type ModeService
- type OnboardingStatusResponse
- type PresetQuestion
- type PresetQuestionAttachment
- type PresetQuestionsResponse
- type PreviewStatusResponse
- type PreviewTokenResponse
- type QuestionsService
- func (s *QuestionsService) GetAllQuestions(lang string) []PresetQuestion
- func (s *QuestionsService) GetPresetQuestionPage(offset, count int, lang string) ([]PresetQuestion, int)
- func (s *QuestionsService) GetPresetQuestions(count int, lang string) []PresetQuestion
- func (s *QuestionsService) GetQuestionsByCategory(category string, lang string) []PresetQuestion
- type SystemMode
- type UpgradeRequest
- type UpgradeResponse
- type UpgradeService
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUsernameRequired is returned when username is empty. ErrUsernameRequired = errors.New("username is required") // ErrPasswordRequired is returned when password is empty. ErrPasswordRequired = errors.New("password is required") // ErrUsersAlreadyExist is returned when preview upgrade is attempted after any user exists. ErrUsersAlreadyExist = errors.New("users already exist") // ErrAdminAlreadyExists is returned when trying to upgrade but admin already exists. ErrAdminAlreadyExists = errors.New("admin already exists") )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles preview mode HTTP requests.
func NewHandler ¶
func NewHandler(modeService *ModeService, upgradeService *UpgradeService, jwtService *auth.JWTService, userService *user.Service) *Handler
NewHandler creates a new preview Handler.
func (*Handler) GetOnboardingStatus ¶
GetOnboardingStatus returns whether the user has seen the onboarding modal. GET /api/v1/preview/onboarding
func (*Handler) GetPresetQuestions ¶
GetPresetQuestions returns a paged selection of preset questions. GET /api/v1/preset-questions?count=4&offset=0&lang=en
func (*Handler) GetPreviewStatus ¶
GetPreviewStatus returns the preview mode status. GET /api/v1/preview/status
func (*Handler) GetPreviewToken ¶
GetPreviewToken generates a temporary token for preview mode. POST /api/v1/preview/token
func (*Handler) GetSystemMode ¶
GetSystemMode returns the current system mode. GET /api/v1/system/mode
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers preview mode routes.
func (*Handler) SetDataDir ¶
SetDataDir sets the data directory for storing onboarding state.
func (*Handler) SetOnboardingSeen ¶
SetOnboardingSeen marks the onboarding as seen. POST /api/v1/preview/onboarding
type MigrationResult ¶
MigrationResult contains per-table row counts updated during preview migration.
type MigrationService ¶
type MigrationService struct {
// contains filtered or unexported fields
}
MigrationService handles migration of preview data to admin account.
func NewMigrationService ¶
func NewMigrationService(db *sql.DB) *MigrationService
NewMigrationService creates a new MigrationService.
func NewMigrationServiceWithReadDB ¶
func NewMigrationServiceWithReadDB(writeDB, readDB *sql.DB) *MigrationService
func (*MigrationService) GetMigrationStatus ¶
func (s *MigrationService) GetMigrationStatus(ctx context.Context) (bool, error)
GetMigrationStatus checks if preview data has been migrated.
func (*MigrationService) MigratePreviewData ¶
func (s *MigrationService) MigratePreviewData(ctx context.Context, adminUserID string) (*MigrationResult, error)
MigratePreviewData migrates all preview mode data to the new admin user.
type ModeService ¶
type ModeService struct {
// contains filtered or unexported fields
}
ModeService provides preview mode detection and management.
func NewModeService ¶
func NewModeService(userService *user.Service) *ModeService
NewModeService creates a new ModeService.
func (*ModeService) GetSystemMode ¶
func (s *ModeService) GetSystemMode(ctx context.Context) (*SystemMode, error)
GetSystemMode returns the current system mode and available features.
func (*ModeService) IsPreviewMode ¶
func (s *ModeService) IsPreviewMode(ctx context.Context) (bool, error)
IsPreviewMode checks if the system is in preview mode. Preview mode is active when no user exists yet.
type OnboardingStatusResponse ¶
type OnboardingStatusResponse struct {
Seen bool `json:"seen"`
}
OnboardingStatusResponse represents the onboarding status response.
type PresetQuestion ¶
type PresetQuestion struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Prompt string `json:"prompt,omitempty"`
Text string `json:"text"`
TextKey string `json:"text_key,omitempty"` // i18n key for frontend translation
Category string `json:"category"`
Tags []string `json:"tags,omitempty"`
Icon string `json:"icon,omitempty"`
EditorialScore int `json:"editorial_score,omitempty"`
Attachments []PresetQuestionAttachment `json:"attachments,omitempty"`
}
PresetQuestion represents a curated preset question.
type PresetQuestionAttachment ¶
type PresetQuestionAttachment struct {
Type string `json:"type"` // "image" or "file"
Name string `json:"name"` // filename
MimeType string `json:"mime_type"` // MIME type
Placeholder string `json:"placeholder"` // reserved for legacy preview payload compatibility
}
PresetQuestionAttachment represents an attachment for a preset question.
type PresetQuestionsResponse ¶
type PresetQuestionsResponse struct {
Questions []PresetQuestion `json:"questions"`
Total int `json:"total"`
NextOffset int `json:"next_offset"`
HasMore bool `json:"has_more"`
}
PresetQuestionsResponse represents the preset questions response.
type PreviewStatusResponse ¶
PreviewStatusResponse represents the preview status response.
type PreviewTokenResponse ¶
PreviewTokenResponse represents the preview token response.
type QuestionsService ¶
type QuestionsService struct {
// contains filtered or unexported fields
}
QuestionsService provides preset questions for preview-related UI.
func NewQuestionsService ¶
func NewQuestionsService() *QuestionsService
NewQuestionsService creates a new QuestionsService.
func (*QuestionsService) GetAllQuestions ¶
func (s *QuestionsService) GetAllQuestions(lang string) []PresetQuestion
GetAllQuestions returns all preset questions for a language.
func (*QuestionsService) GetPresetQuestionPage ¶
func (s *QuestionsService) GetPresetQuestionPage(offset, count int, lang string) ([]PresetQuestion, int)
GetPresetQuestionPage returns a deterministic slice of preset questions for incremental loading.
func (*QuestionsService) GetPresetQuestions ¶
func (s *QuestionsService) GetPresetQuestions(count int, lang string) []PresetQuestion
GetPresetQuestions returns the leading preset questions for a language.
func (*QuestionsService) GetQuestionsByCategory ¶
func (s *QuestionsService) GetQuestionsByCategory(category string, lang string) []PresetQuestion
GetQuestionsByCategory returns questions filtered by category.
type SystemMode ¶
type SystemMode struct {
Mode string `json:"mode"` // "preview" or "normal"
Features map[string]bool `json:"features"` // Available features
}
SystemMode represents the current system mode.
type UpgradeRequest ¶
UpgradeRequest represents a request to upgrade from preview mode.
type UpgradeResponse ¶
type UpgradeResponse struct {
Success bool `json:"success"`
User *user.User `json:"user"`
DataMigrated bool `json:"data_migrated"`
MigratedCounts map[string]int64 `json:"migrated_counts,omitempty"`
}
UpgradeResponse represents the response after successful upgrade.
type UpgradeService ¶
type UpgradeService struct {
// contains filtered or unexported fields
}
UpgradeService handles upgrading from preview mode to normal mode.
func NewUpgradeService ¶
func NewUpgradeService(userService *user.Service, db *sql.DB) *UpgradeService
NewUpgradeService creates a new UpgradeService.
func NewUpgradeServiceWithReadDB ¶
func NewUpgradeServiceWithReadDB(userService *user.Service, writeDB, readDB *sql.DB) *UpgradeService
NewUpgradeServiceWithReadDB creates a new UpgradeService with separate write and read database handles for preview migration status checks.
func (*UpgradeService) Upgrade ¶
func (s *UpgradeService) Upgrade(ctx context.Context, req *UpgradeRequest) (*UpgradeResponse, error)
Upgrade creates an admin user and migrates preview data.