41 lines
1 KiB
Go
41 lines
1 KiB
Go
package application
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
type SystemRepository interface {
|
|
DatabaseHealth(context.Context) error
|
|
OwnerExists(context.Context) (bool, error)
|
|
}
|
|
|
|
type SetupStatus struct {
|
|
Initialized bool `json:"initialized"`
|
|
Phase string `json:"phase"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
type SystemService struct {
|
|
repository SystemRepository
|
|
version string
|
|
}
|
|
|
|
func NewSystemService(repository SystemRepository, version string) *SystemService {
|
|
return &SystemService{repository: repository, version: version}
|
|
}
|
|
|
|
func (s *SystemService) Readiness(ctx context.Context) error {
|
|
if err := s.repository.DatabaseHealth(ctx); err != nil {
|
|
return fmt.Errorf("database health: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *SystemService) SetupStatus(ctx context.Context) (SetupStatus, error) {
|
|
initialized, err := s.repository.OwnerExists(ctx)
|
|
if err != nil {
|
|
return SetupStatus{}, fmt.Errorf("read owner setup state: %w", err)
|
|
}
|
|
return SetupStatus{Initialized: initialized, Phase: "phase-1", Version: s.version}, nil
|
|
}
|