add config to tasks
use fmt.Errorf
This commit is contained in:
@@ -3,43 +3,55 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"fmt"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTask(interfaceType Interface, aboutScreen tea.Model, questionnaire tea.Model) *Task {
|
type Task struct {
|
||||||
|
Config TaskConfig
|
||||||
|
interfaceType Interface
|
||||||
|
aboutScreen tea.Model
|
||||||
|
questionnaire tea.Model
|
||||||
|
|
||||||
|
validateFunc ValidateFunc
|
||||||
|
dbStateFunc DbStateFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTask(aboutScreen tea.Model, questionnaire tea.Model) *Task {
|
||||||
return &Task{
|
return &Task{
|
||||||
interfaceType: interfaceType,
|
|
||||||
aboutScreen: aboutScreen,
|
aboutScreen: aboutScreen,
|
||||||
questionnaire: questionnaire,
|
questionnaire: questionnaire,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) SetValidateFunc(fn ValidateFunc) {
|
func (t *Task) SetConfigFunc(fn ConfigFunc) {
|
||||||
t.validateFunc = fn
|
t.Config = fn()
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Task) SetDbStateFunc(fn DbStateFunc) {
|
|
||||||
t.dbStateFunc = fn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) SetInterface(interfaceType Interface) {
|
func (t *Task) SetInterface(interfaceType Interface) {
|
||||||
t.interfaceType = interfaceType
|
t.interfaceType = interfaceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) Validate(ctx context.Context, svc *service.Services) (bool, error) {
|
func (t *Task) SetDbStateFunc(fn DbStateFunc) {
|
||||||
if t.validateFunc == nil {
|
t.dbStateFunc = fn
|
||||||
return false, errors.New("validateFunc is not set")
|
|
||||||
}
|
|
||||||
return t.validateFunc(ctx, svc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) MigrateToTask(ctx context.Context, svc *service.Services, task *Task) error {
|
func (t *Task) SetValidateFunc(fn ValidateFunc) {
|
||||||
t = task
|
t.validateFunc = fn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Task) Initialize(ctx context.Context, svc *service.Services) error {
|
||||||
if t.dbStateFunc == nil {
|
if t.dbStateFunc == nil {
|
||||||
return errors.New("dbStateFunc is not set")
|
return fmt.Errorf("dbStateFunc is not set")
|
||||||
}
|
}
|
||||||
return t.dbStateFunc(ctx, svc)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user