add task system and task model for viewing task details
This commit is contained in:
45
cmd/survey/tasks/task.go
Normal file
45
cmd/survey/tasks/task.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// task.go
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
func NewTask(interfaceType Interface, aboutScreen tea.Model, questionnaire tea.Model) *Task {
|
||||
return &Task{
|
||||
interfaceType: interfaceType,
|
||||
aboutScreen: aboutScreen,
|
||||
questionnaire: questionnaire,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Task) SetValidateFunc(fn ValidateFunc) {
|
||||
t.validateFunc = fn
|
||||
}
|
||||
|
||||
func (t *Task) SetDbStateFunc(fn DbStateFunc) {
|
||||
t.dbStateFunc = fn
|
||||
}
|
||||
|
||||
func (t *Task) SetInterface(interfaceType Interface) {
|
||||
t.interfaceType = interfaceType
|
||||
}
|
||||
|
||||
func (t *Task) Validate(ctx context.Context, svc *service.Services) (bool, error) {
|
||||
if t.validateFunc == nil {
|
||||
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 {
|
||||
t = task
|
||||
if t.dbStateFunc == nil {
|
||||
return errors.New("dbStateFunc is not set")
|
||||
}
|
||||
return t.dbStateFunc(ctx, svc)
|
||||
}
|
||||
Reference in New Issue
Block a user