planner/plan/command/list.go

48 lines
933 B
Go
Raw Normal View History

2024-09-30 07:34:40 +02:00
package command
import (
"fmt"
"go-mod.ewintr.nl/planner/plan/storage"
)
2024-10-29 07:22:04 +01:00
type List struct {
localIDRepo storage.LocalID
2024-12-24 08:00:23 +01:00
taskRepo storage.Task
2024-09-30 07:34:40 +02:00
}
2024-12-24 08:00:23 +01:00
func NewList(localIDRepo storage.LocalID, taskRepo storage.Task) Command {
2024-10-29 07:22:04 +01:00
return &List{
localIDRepo: localIDRepo,
2024-12-24 08:00:23 +01:00
taskRepo: taskRepo,
2024-10-03 07:32:48 +02:00
}
2024-09-30 07:34:40 +02:00
}
2024-10-29 07:22:04 +01:00
func (list *List) Execute(main []string, flags map[string]string) error {
if len(main) > 0 && main[0] != "list" {
return ErrWrongCommand
}
return list.do()
}
func (list *List) do() error {
localIDs, err := list.localIDRepo.FindAll()
2024-10-03 07:32:48 +02:00
if err != nil {
return fmt.Errorf("could not get local ids: %v", err)
}
2024-12-24 08:00:23 +01:00
all, err := list.taskRepo.FindAll()
2024-10-03 07:32:48 +02:00
if err != nil {
return err
}
for _, e := range all {
lid, ok := localIDs[e.ID]
if !ok {
return fmt.Errorf("could not find local id for %s", e.ID)
2024-09-30 07:34:40 +02:00
}
2024-12-19 12:06:03 +01:00
fmt.Printf("%s\t%d\t%s\t%s\t%s\n", e.ID, lid, e.Title, e.Date.String(), e.Duration.String())
2024-09-30 07:34:40 +02:00
}
2024-10-03 07:32:48 +02:00
return nil
2024-09-30 07:34:40 +02:00
}