refactor for better maintainability and readabilty

This commit is contained in:
Robin Olsen
2026-02-17 11:11:54 +01:00
parent a38e32aa78
commit 279adb157e
7 changed files with 68 additions and 73 deletions

View File

@@ -16,12 +16,15 @@ type Task struct {
validateFunc ValidateFunc
dbStateFunc DbStateFunc
svc *service.Services
}
func NewTask(aboutScreen tea.Model, questionnaire tea.Model) *Task {
func NewTask(svc *service.Services, aboutScreen tea.Model, questionnaire tea.Model) *Task {
return &Task{
aboutScreen: aboutScreen,
questionnaire: questionnaire,
svc: svc,
}
}
@@ -47,6 +50,20 @@ func (t *Task) StartInterface(ctx context.Context, cfg TaskConfig) error {
return t.interfaceType.Run(ctx, cfg)
}
func (t *Task) Initialize(ctx context.Context) error {
if t.dbStateFunc == nil {
return fmt.Errorf("dbStateFunc is not set")
}
return t.dbStateFunc(ctx, t.svc)
}
func (t *Task) Validate(ctx context.Context) (bool, error) {
if t.validateFunc == nil {
return false, fmt.Errorf("validateFunc is not set")
}
return t.validateFunc(ctx, t.svc)
}
func (t *Task) StartQuestionnaire() error {
if t.questionnaire == nil {
return fmt.Errorf("questionnaire is not set")
@@ -76,17 +93,3 @@ func (t *Task) SetDbStateFunc(fn DbStateFunc) {
func (t *Task) SetValidateFunc(fn ValidateFunc) {
t.validateFunc = fn
}
func (t *Task) Initialize(ctx context.Context, svc *service.Services) error {
if t.dbStateFunc == nil {
return fmt.Errorf("dbStateFunc is not set")
}
return t.dbStateFunc(ctx, svc)
}
func (t *Task) Validate(ctx context.Context, svc *service.Services) (bool, error) {
if t.validateFunc == nil {
return false, fmt.Errorf("validateFunc is not set")
}
return t.validateFunc(ctx, svc)
}