Skip to content

Refactor recent food module for improved structure and functionality#1438

Merged
marcuscastelo merged 31 commits intorc/v0.16.0from
marcuscastelo/issue1404
Mar 24, 2026
Merged

Refactor recent food module for improved structure and functionality#1438
marcuscastelo merged 31 commits intorc/v0.16.0from
marcuscastelo/issue1404

Conversation

@marcuscastelo
Copy link
Copy Markdown
Owner

@marcuscastelo marcuscastelo commented Dec 3, 2025

Restructure the recent food module by moving components, simplifying data management, and enhancing real-time updates. This refactor improves code organization and reduces unnecessary exports.

Fix #1404

Copilot AI review requested due to automatic review settings December 3, 2025 18:33
@marcuscastelo marcuscastelo self-assigned this Dec 3, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
macroflows Ready Ready Preview, Comment Mar 24, 2026 8:17pm

@github-actions github-actions bot added backend Backend-specific issue or change complexity-medium Medium implementation complexity refactor Code refactoring required subissue labels Dec 3, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures the recent food module by introducing a clean architecture pattern with distinct layers, moving components to more appropriate locations, and preparing the groundwork for real-time synchronization capabilities.

Key Changes

  • Introduced a service layer (recentFoodCrudService) to separate business logic from use case orchestration
  • Consolidated recent food operations into a centralized recentFoodUseCases module with consistent error handling and user feedback
  • Refactored the realtime update system to use dependency-injected callbacks instead of directly coupling to a cache store
  • Moved RemoveFromRecentButton from common components to the recent-food module for better cohesion
  • Cleaned up database schema by removing deprecated user_id_old fields

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/shared/supabase/supabase.ts Added TODO comment about implementing user-specific realtime subscriptions
src/shared/supabase/database.types.ts Removed deprecated user_id_old fields from recent_foods table and added users_duplicate table
src/sections/search/ui/openTemplateSearchModal.tsx Added template refetch on modal close to update recent foods list
src/sections/search/components/TemplateSearchResultItem.tsx Updated import path for RemoveFromRecentButton after component relocation
src/sections/search/components/TemplateSearchModal.tsx Simplified item tracking logic by delegating to recentFoodUseCases.touchRecentFoodForItem
src/modules/template-search/application/usecases/templateSearchState.ts Updated to use recentFoodUseCases.fetchUserRecentFoodsAsTemplates and added TODO for reactive signals
src/modules/template-search/application/tests/templateSearchLogic.test.ts Updated test mocks to use renamed fetchUserRecentFoodsAsTemplates method
src/modules/template-search/application/templateSearchLogic.ts Renamed dependency from fetchUserRecentFoods to fetchUserRecentFoodsAsTemplates for clarity
src/modules/recent-food/ui/tests/RemoveFromRecentButton.test.tsx Removed redundant API integration and toast promise tests, focusing on business logic tests
src/modules/recent-food/ui/RemoveFromRecentButton.tsx Simplified to use recentFoodUseCases and removed empty catch block
src/modules/recent-food/infrastructure/supabase/supabaseRecentFoodGateway.ts Added type export for RecentFoodGateway to support dependency injection
src/modules/recent-food/infrastructure/supabase/realtime.ts Refactored to accept callback functions as parameters instead of directly coupling to cache store
src/modules/recent-food/infrastructure/signals/recentFoodCacheStore.ts Deleted entire file as part of cache refactoring
src/modules/recent-food/infrastructure/recentFoodRepository.ts Converted to factory function accepting gateway as parameter; improved error log messages with [NON-FATAL] prefix
src/modules/recent-food/domain/recentFood.ts Removed comment-only line (cleanup)
src/modules/recent-food/application/usecases/recentFoodUseCases.ts New consolidated use cases module with consistent error handling, toast notifications, and touchRecentFoodForItem orchestration
src/modules/recent-food/application/usecases/recentFoodCrud.ts Deleted entire file, functionality moved to recentFoodUseCases.ts
src/modules/recent-food/application/services/recentFoodCrudService.ts New service layer that wraps repository methods without side effects (no toasts/errors)

Comment thread src/modules/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread src/shared/supabase/database.types.ts
Comment thread src/modules/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread src/sections/search/components/TemplateSearchModal.tsx Outdated
Comment thread src/modules/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread src/modules/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread src/modules/diet/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread src/sections/search/ui/openTemplateSearchModal.tsx Outdated
Comment thread src/modules/diet/recent-food/infrastructure/supabase/realtime.ts
@marcuscastelo marcuscastelo changed the base branch from rc/v0.15.0 to rc/v0.16.0 December 6, 2025 15:06
@marcuscastelo marcuscastelo requested a review from Copilot December 6, 2025 15:07
Removed the display of guest terms acceptance status in the warning message.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 39 changed files in this pull request and generated 6 comments.

Comment thread src/modules/diet/recent-food/application/usecases/touchRecentFood.ts Outdated
Comment thread src/modules/diet/recent-food/ui/RemoveFromRecentButton.tsx Outdated
Comment thread src/modules/diet/recent-food/application/usecases/deps.ts Outdated
@marcuscastelo marcuscastelo changed the base branch from rc/v0.16.0 to marcuscastelo/issue1447-remove-shims December 6, 2025 18:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 58 out of 59 changed files in this pull request and generated 4 comments.

Comment thread src/modules/diet/macro-profile/application/usecases/macroProfileUseCases.ts Outdated
Comment thread src/modules/diet/recent-food/application/usecases/recentFoodUseCases.ts Outdated
Comment thread biome.jsonc
Comment thread src/modules/diet/macro-target/application/macroTargetUseCases.ts Outdated
Base automatically changed from marcuscastelo/issue1447-remove-shims to marcuscastelo/issue1447 March 23, 2026 18:34
Base automatically changed from marcuscastelo/issue1447 to rc/v0.16.0 March 23, 2026 22:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 37 changed files in this pull request and generated 12 comments.

Comment thread src/modules/diet/recent-food/ui/RemoveFromRecentButton.tsx Outdated
Comment thread src/sections/search/components/TemplateSearchModal.tsx Outdated
Comment thread src/sections/search/components/TemplateSearchModal.tsx
Comment thread src/modules/template-search/application/usecases/templateSearchState.ts Outdated
Comment thread src/sections/search/ui/openTemplateSearchModal.tsx
Comment thread biome.jsonc
Comment thread src/sections/search/components/TemplateSearchModal.tsx
Comment thread src/modules/diet/recent-food/application/usecases/touchRecentFoodForItem.ts Outdated
Comment thread src/modules/diet/recent-food/application/usecases/touchRecentFoodForItem.ts Outdated
@marcuscastelo marcuscastelo merged commit 9c07659 into rc/v0.16.0 Mar 24, 2026
5 checks passed
@marcuscastelo marcuscastelo deleted the marcuscastelo/issue1404 branch March 24, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend-specific issue or change complexity-medium Medium implementation complexity refactor Code refactoring required subissue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

recent-food: Encapsulate infra exports — export only factories

2 participants