diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/constants.go | 2 | ||||
| -rw-r--r-- | internal/models/types.go | 35 |
2 files changed, 35 insertions, 2 deletions
diff --git a/internal/config/constants.go b/internal/config/constants.go index a199404..9eba843 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -39,7 +39,7 @@ const ( // Session settings const ( - SessionLifetime = 24 * time.Hour + SessionLifetime = 7 * 24 * time.Hour // 7 days for mobile convenience ) // Rate limiting 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"` |
