Skip to content

Add meal plan CRUD routes - #49

Merged
leslyVillanueva1020 merged 4 commits into
mainfrom
doyoung/meal-plan
Oct 17, 2026
Merged

leslyVillanueva1020 merged 4 commits into
mainfrom
doyoung/meal-plan

Conversation

@Yooze0x4c8

Copy link
Copy Markdown
Collaborator

Closes #45

What changed

  • Added MealPlanController for /api/v1/meal-plans
    • GET /api/v1/meal-plans?page&size: paginated list of the signed-in user's plans (content + page metadata, size 1–100, page ≥ 0)
    • POST /api/v1/meal-plans: 201 with a Location header, starts with empty entries
    • GET /api/v1/meal-plans/{mealPlanId}: plan with its entries
    • PATCH /api/v1/meal-plans/{mealPlanId}: changes weekStart only, entries are kept
    • DELETE /api/v1/meal-plans/{mealPlanId}: 204, deletes the plan's entries but keeps the recipes
  • Added MealPlanService and MealPlanRepository. Lookups are scoped to the owner, so a missing plan and another user's plan both return 404 (not 403)
  • Added request/response records (MealPlanCreate, MealPlanPatch, MealPlanResponse, MealPlanEntryResponse) so entities are never serialized directly
  • Added MealPlan.changeWeekStart
  • Enabled RFC 9457 Problem Details (spring.mvc.problemdetails.enabled) for 400/404 errors
  • Set hibernate.default_batch_fetch_size to avoid N+1 queries when listing entries
  • Added springdoc-openapi 3.1.1 (Swagger UI at /swagger-ui.html, docs at /v3/api-docs)

Depends on #48

This PR works on top of main without Spring Security, so some parts are temporary and marked with TODO(#48):

How I tested it

  • Unit tests pass locally (./gradlew check, service package coverage above the 70% floor)
    • MealPlanServiceTest: 404 for missing/other users' plans, empty list, new plan is owned and empty, update keeps entries, delete removes the plan from its owner
    • MealPlanServiceJpaTest: deleting a plan removes entries but keeps recipes; other users' plans are hidden from get and list
    • MealPlanControllerTest: page shape, 400 for bad paging / missing or invalid date / empty PATCH body, 201 + Location, 204, 404 as application/problem+json
    • ApiApplicationTests: /v3/api-docs and /swagger-ui.html are served
  • If the API contract changed, docs/openapi.yaml is updated and lints clean. Not applicable: the implementation follows the existing contract, and docs/openapi.yaml was not changed.

Reviewers

2 approving teammates who are not the author (1 for a team of 3).

- Missing or other users' meal plans return 404
- Delete goes through User.removeMealPlan so entries are removed and recipes are kept
- Added MealPlanServiceTest (Mockito) and MealPlanServiceJpaTest (cascade, ownership)
- GET list (paginated, size 1-100), POST, GET by id, PATCH, DELETE
- Enabled RFC 9457 Problem Details for errors
- Set hibernate default_batch_fetch_size to avoid N+1 on entries
- Added MealPlanControllerTest for 200/201/204/400/404
- springdoc-openapi-starter-webmvc-ui 3.1.1 (Spring Boot 4)
- Test that /v3/api-docs and /swagger-ui.html are served

@Solian21 Solian21 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it looks really good overall. The CRUD routes are pretty well organized and user ownership is enforced through the repository queries.

@annabelleb20 annabelleb20 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I really like how this is formatted, hopefully all the TODOs are able to be covered by my PR

@leslyVillanueva1020
leslyVillanueva1020 merged commit 880cf2b into main Oct 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

As a signed-in user, I want to create, view, update, and delete my weekly meal plans so that I can organize which recipes I'll eat each week.

4 participants