2021-08-19 07:06:18 +02:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
2021-09-19 11:59:26 +02:00
|
|
|
"ewintr.nl/gte/internal/storage"
|
2021-08-19 07:06:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrCouldNotFetchProjects = errors.New("could not fetch projects")
|
|
|
|
)
|
|
|
|
|
|
|
|
type Projects struct {
|
|
|
|
local storage.LocalRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProjects(local storage.LocalRepository) *Projects {
|
|
|
|
return &Projects{
|
|
|
|
local: local,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Projects) Process() ([]string, error) {
|
2021-08-25 06:52:48 +02:00
|
|
|
allTasks, err := p.local.FindAll()
|
|
|
|
if err != nil {
|
|
|
|
return []string{}, fmt.Errorf("%w: %v", ErrCouldNotFetchProjects, err)
|
2021-08-19 07:06:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
knownMap := map[string]bool{}
|
|
|
|
for _, t := range allTasks {
|
|
|
|
knownMap[t.Project] = true
|
|
|
|
}
|
|
|
|
known := []string{}
|
|
|
|
for p := range knownMap {
|
|
|
|
known = append(known, p)
|
|
|
|
}
|
|
|
|
sort.Strings(known)
|
|
|
|
|
|
|
|
return known, nil
|
|
|
|
}
|