diff options
Diffstat (limited to 'internal/handlers/timeline_logic.go')
| -rw-r--r-- | internal/handlers/timeline_logic.go | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/internal/handlers/timeline_logic.go b/internal/handlers/timeline_logic.go index 4334f6d..adfa406 100644 --- a/internal/handlers/timeline_logic.go +++ b/internal/handlers/timeline_logic.go @@ -48,32 +48,9 @@ func BuildTimeline(ctx context.Context, s *store.Store, tasksClient api.GoogleTa return nil, err } - // Group meals by date+mealType key - type mealKey struct { - date string - mealType string - } - mealGroups := make(map[mealKey][]models.Meal) - for _, meal := range meals { - key := mealKey{ - date: meal.Date.Format("2006-01-02"), - mealType: meal.MealType, - } - mealGroups[key] = append(mealGroups[key], meal) - } - - // Create combined timeline items for each group - for _, group := range mealGroups { - if len(group) == 0 { - continue - } - - // Use first meal as base - firstMeal := group[0] - mealTime := firstMeal.Date - - // Apply Meal time defaults - switch firstMeal.MealType { + for _, cm := range groupMeals(meals) { + mealTime := cm.Date + switch cm.MealType { case "breakfast": mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), config.BreakfastHour, 0, 0, 0, mealTime.Location()) case "lunch": @@ -84,20 +61,13 @@ func BuildTimeline(ctx context.Context, s *store.Store, tasksClient api.GoogleTa mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), config.LunchHour, 0, 0, 0, mealTime.Location()) } - // Combine recipe names with " + " - var names []string - for _, m := range group { - names = append(names, m.RecipeName) - } - combinedTitle := strings.Join(names, " + ") - item := models.TimelineItem{ - ID: firstMeal.ID, + ID: cm.ID, Type: models.TimelineItemTypeMeal, - Title: combinedTitle, + Title: strings.Join(cm.RecipeNames, " + "), Time: mealTime, - URL: firstMeal.RecipeURL, // Use first meal's URL - OriginalItem: group, // Store all meals + URL: cm.RecipeURL, + OriginalItem: cm.Meals, IsCompleted: false, Source: "plantoeat", } |
