refactor to use Tasker interface instead of Task
add tasker register for registering tasks for extiensibility
This commit is contained in:
71
cmd/survey/tasks/codingTask.go
Normal file
71
cmd/survey/tasks/codingTask.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
taskui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
const codingDescription = `You are tasked with writing a simple function.
|
||||
|
||||
Write a function that takes two integers and returns their sum.
|
||||
The function should be named "Add" and be part of the "coding" package.`
|
||||
|
||||
func init() {
|
||||
task.Register("coding_task", func(svc *service.Services) task.Tasker {
|
||||
return NewCodingTask(svc)
|
||||
})
|
||||
}
|
||||
|
||||
type CodingTask struct {
|
||||
svc *service.Services
|
||||
}
|
||||
|
||||
func NewCodingTask(svc *service.Services) *CodingTask {
|
||||
return &CodingTask{svc: svc}
|
||||
}
|
||||
|
||||
func (t *CodingTask) Config() task.TaskConfig {
|
||||
return task.TaskConfig{
|
||||
IssuePrefix: "pm",
|
||||
BeadsDBPath: "./.pm/db.db",
|
||||
StatisticsStoragePath: "./.pm/coding-stats.json",
|
||||
WebAddress: "localhost:8080",
|
||||
}
|
||||
}
|
||||
|
||||
func (t *CodingTask) Details() taskui.TaskDetails {
|
||||
return taskui.TaskDetails{
|
||||
Title: "Coding Task",
|
||||
Description: codingDescription,
|
||||
TimeToComplete: "10m",
|
||||
Difficulty: "Easy",
|
||||
}
|
||||
}
|
||||
|
||||
func (t *CodingTask) Questions(interfaceType task.InterfaceType) taskui.Questions {
|
||||
return taskui.Questions{
|
||||
huh.NewGroup(huh.NewConfirm().Title("Did you complete the coding task?")),
|
||||
huh.NewGroup(
|
||||
huh.NewSelect[int]().
|
||||
Options(
|
||||
huh.NewOption("Very easy", 1),
|
||||
huh.NewOption("Easy", 2),
|
||||
huh.NewOption("Moderate", 3),
|
||||
huh.NewOption("Hard", 4),
|
||||
).
|
||||
Title("How difficult was the task?"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *CodingTask) Setup(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *CodingTask) Validate(ctx context.Context) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user