diff options
Diffstat (limited to 'internal/models')
| -rw-r--r-- | internal/models/types.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/internal/models/types.go b/internal/models/types.go index ab06ea2..8ec2095 100644 --- a/internal/models/types.go +++ b/internal/models/types.go @@ -1,6 +1,10 @@ package models -import "time" +import ( + "sort" + "strings" + "time" +) // Task represents a task from Todoist type Task struct { @@ -60,6 +64,35 @@ type ShoppingCategory struct { Items []UnifiedShoppingItem } +// FlattenItemsForStore extracts all items for a specific store, sorted by checked status then name +func FlattenItemsForStore(stores []ShoppingStore, storeName string) []UnifiedShoppingItem { + var items []UnifiedShoppingItem + for _, store := range stores { + if strings.EqualFold(store.Name, storeName) { + for _, cat := range store.Categories { + items = append(items, cat.Items...) + } + } + } + // Sort: unchecked first, then by name + sort.Slice(items, func(i, j int) bool { + if items[i].Checked != items[j].Checked { + return !items[i].Checked + } + return items[i].Name < items[j].Name + }) + return items +} + +// StoreNames returns the names of all stores +func StoreNames(stores []ShoppingStore) []string { + names := make([]string, len(stores)) + for i, store := range stores { + names[i] = store.Name + } + return names +} + // List represents a Trello list type List struct { ID string `json:"id"` |
