Skip to content

feat(issue-2): complete Food Item Library with error handling and DB sequence fix - #115

Closed
AtCloudDiwash wants to merge 22 commits into
codepath:mainfrom
NourdotSiwar:add/Issue-2-add-guardrails
Closed

feat(issue-2): complete Food Item Library with error handling and DB sequence fix#115
AtCloudDiwash wants to merge 22 commits into
codepath:mainfrom
NourdotSiwar:add/Issue-2-add-guardrails

Conversation

@AtCloudDiwash

Copy link
Copy Markdown

Closes Issue #2 — Food Item Library

This PR completes the Food Item Library feature by hardening all API
interactions with proper error handling and fixing a critical database
sequence bug that prevented new food items from being created.


Changes Made

🛡️ Error Handling & Guard Rails

  • Wrapped all unguarded fetch calls in CreateMeal.jsx, Meals.jsx,
    Dashboard.jsx, and FoodLibrary.jsx with res.ok checks and try/catch blocks
  • Added a shared .error-message CSS class in index.css — red banner
    with border, used across all pages

🗑️ Delete Protection

  • handleDelete in FoodLibrary.jsx now checks res.ok before removing
    an item from the UI
  • Shows a clear error message when a food item cannot be deleted because
    it is referenced in a meal

🗄️ Database Sequence Fix

  • Added setval after each seed function in reset.js to sync PostgreSQL
    auto-increment sequences with hardcoded seed IDs — prevents duplicate
    key errors on first insert after seeding

    Test Plan

✅ Works Fine

  • Create a new food item → saves successfully, appears in the grid
  • Edit a food item inline → modal pre-fills, saves and closes correctly
  • Delete a food item not linked to any meal → disappears from the grid
  • Run the reset/seed script → all records insert without duplicate key errors

❌ Error Cases

  • Delete a food item used in a meal → item stays, red error banner appears
  • Stop the backend, reload /foods → red error banner instead of crash
  • Stop the backend, reload /meals → red error banner instead of crash

NourdotSiwar and others added 22 commits April 3, 2026 13:38
Update milestone2.md to mark completion of pitch preparation and refl…
…eting food items

- Implemented AddFoodItem page for adding new food items with nutritional information.
- Created FoodLibrary page to manage food items with search functionality.
- Developed CreateMeal page to allow users to create meals from food items.
- Added Dashboard page to track daily macro progress.
- Introduced Goals page for setting daily macro targets.
- Implemented Meals page to view logged meals with date filtering.
- Added CSS styles for new components and pages.
- Configured Vite for development with API proxy.
- Updated server routes for meals to include fetching by user ID.
- Enhanced dotenv configuration for better path handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants