Repository navigation
Add, view, change, and remove meal plan entries - #60
Merged
Merged
Conversation
Yooze0x4c8
requested review from
Solian21,
annabelleb20 and
leslyVillanueva1020
as code owners
October 21, 2026 23:43
annabelleb20
previously approved these changes
Oct 22, 2026
annabelleb20
left a comment
Collaborator
There was a problem hiding this comment.
Overall I think this looks great, I like how you wrote the additional jpa tests and I think everything looks fine in the code. Personally I'm fine with the new rule and behavior change with the mealplan entry stuff, I think it makes sense and works for our project.
Solian21
requested changes
Oct 22, 2026
| // A user can plan their own recipes and the prepopulated ones; anything else is hidden as 404. | ||
| private Recipe findUsableRecipe(User owner, Long recipeId) { | ||
| return recipeRepository.findById(recipeId) | ||
| .filter(r -> r.isPrepopulated() || r.getOwner() == owner) |
Owner
There was a problem hiding this comment.
This currently compares the Java objects. This could cause the users own recipe to be rejected with a 404 error. I think it would be better to compare the owner id or by recipe id and the owner.
Solian21
approved these changes
Oct 22, 2026
Solian21
left a comment
Owner
There was a problem hiding this comment.
Nice fix. This looks good to me!
annabelleb20
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #59
What changed
Adds the meal plan entry endpoints, so users can put recipes into a meal plan and manage them.
New endpoints
POST /api/v1/meal-plans/{mealPlanId}/entries: adds a recipe to a meal plan. Returns 201 with aLocationheader. All ofrecipeId,plannedDate, andmealTypeare required.GET /api/v1/meal-plans/{mealPlanId}/entries: lists the meal plan's entries.PATCH /api/v1/meal-plans/{mealPlanId}/entries/{entryId}: changes only the fields sent. An empty body is 400.DELETE /api/v1/meal-plans/{mealPlanId}/entries/{entryId}: returns 204. The recipe is kept.Rules
plannedDatemust be within the meal plan's week (weekStartthroughweekStart+ 6 days). Otherwise POST and PATCH return 400. It is checked in theMealPlanEntryentity, so every path follows it.PATCH /api/v1/meal-plans/{id}with a newweekStartnow moves the plan's entries by the same number of days, so they stay on the same weekday inside the new week. Before, entries were left unchanged.Bug fix in existing code (
Recipe.java,MealPlan.java)add/removeMealPlanEntrycomparedentry.getRecipe()/entry.getMealPlan()tothiswith==. When the entry is loaded from the database, the getter returns a Hibernate lazy proxy, not the real entity, so the check always failed and threwIllegalArgumentException(500 in the running app). Existing tests built entities withnew, so no proxy was involved and the bug never showed up. The fix compares againstHibernate.unproxy(...).MealPlanServiceJpaTestnow reloads entities from the database and covers this.Other
MealPlanEntry: addedchangeRecipe,changePlannedDate, andchangeMealType.docs/openapi.yaml: documented the week rule onplannedDate.MealPlanEntryPersistenceTest: changed dates that were outside the plan's week.How I tested it
./gradlew test, 109 tests, 0 failures)docs/openapi.yamlis updated and lints clean (npx @redocly/cli lint docs/openapi.yaml)New tests:
MealPlanServiceTest: partial updates, moving to another recipe, rejected recipes, entry not in the plan, the week boundary (day 0 and day 6 are allowed, day -1 and day 7 are not), and entries moving when the week changes.MealPlanServiceJpaTest(real database): deleting an entry keeps the recipe, changing the recipe after reloading from the database, and a new entry saved with a generated id.MealPlanControllerTest: 200/201/204 responses, theLocationheader, 400 for missing or invalid fields, an empty PATCH body, or a date outside the week, 404 as Problem Details, and 401 without a token.Reviewers
2 approving teammates who are not the author (1 for a team of 3).