diff --git a/internal/config/config.go b/internal/config/config.go index 0ab0ab35714edc6085649a2da9c56791ba82bdcb..a51c4ad7a240f52495b1093bf03d003a42b03d99 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -39,31 +39,31 @@ type Defaults struct { // Area represents a Lunatask area of life with its goals. type Area struct { - ID string `toml:"id"` - Name string `toml:"name"` - Key string `toml:"key"` - Goals []Goal `toml:"goals"` + ID string `json:"id" toml:"id"` + Name string `json:"name" toml:"name"` + Key string `json:"key" toml:"key"` + Goals []Goal `json:"goals" toml:"goals"` } // Goal represents a goal within an area. type Goal struct { - ID string `toml:"id"` - Name string `toml:"name"` - Key string `toml:"key"` + ID string `json:"id" toml:"id"` + Name string `json:"name" toml:"name"` + Key string `json:"key" toml:"key"` } // Notebook represents a Lunatask notebook for notes. type Notebook struct { - ID string `toml:"id"` - Name string `toml:"name"` - Key string `toml:"key"` + ID string `json:"id" toml:"id"` + Name string `json:"name" toml:"name"` + Key string `json:"key" toml:"key"` } // Habit represents a trackable habit. type Habit struct { - ID string `toml:"id"` - Name string `toml:"name"` - Key string `toml:"key"` + ID string `json:"id" toml:"id"` + Name string `json:"name" toml:"name"` + Key string `json:"key" toml:"key"` } // Path returns the path to the config file. @@ -168,3 +168,29 @@ func (a *Area) GoalByKey(key string) *Goal { return nil } + +// GoalMatch pairs a goal with its parent area. +type GoalMatch struct { + Goal *Goal + Area *Area +} + +// FindGoalsByKey returns all goals matching the given key across all areas. +func (c *Config) FindGoalsByKey(key string) []GoalMatch { + var matches []GoalMatch + + for i := range c.Areas { + area := &c.Areas[i] + + for j := range area.Goals { + if area.Goals[j].Key == key { + matches = append(matches, GoalMatch{ + Goal: &area.Goals[j], + Area: area, + }) + } + } + } + + return matches +}