Skip to content

Add create and update restaurant endpoints (#21, #22) - #41

Merged
CookieLynx merged 7 commits into
mainfrom
feature/21-22-create-update-restaurant
Oct 17, 2026
Merged

CookieLynx merged 7 commits into
mainfrom
feature/21-22-create-update-restaurant

Conversation

@sonoftirit

Copy link
Copy Markdown
Collaborator

Adds POST /restaurants and PATCH /restaurants/{restaurant_id} with the service logic and tests.

Closes #21
Closes #22
Closes #29

Note: this branch has Casey's #39 merged in because it needs save_restaurants. Please merge this only after #39 is merged, then this PR will only show my changes.

Create (POST /restaurants, body: RestaurantCreate)

  • 201 with the new restaurant. The server sets the id and type, and new restaurants start with hasMenu: null (works with the "uncategorized section" plan for menu items).
  • 409 if a restaurant with the same name and address already exists. I check both because chains share names (we already have Starbucks etc.).
  • 422 for invalid input (from the request model).

Update (PATCH /restaurants/{restaurant_id}, body: RestaurantUpdate)

  • 200 with the updated restaurant. Only the fields sent are changed, id and menu can't be changed.
  • 404 for an unknown id, 409 if the change would make it a duplicate of another restaurant, 422 for invalid or empty input.

Design:

  • Business rules (duplicate check, not found, building the full restaurant) are in the service. Routes only turn the errors into status codes.
  • Added RestaurantNotFoundError and DuplicateRestaurantError in core/exceptions.py so routes don't have to guess from ValueError, which is already used for invalid data files. Might be good for us to use these for "not found" everywhere later.
  • Both endpoints have a summary, description and their error codes in /docs.

Testing:

  • test_restaurant_management_service.py: service tests with a mock repository.
  • test_restaurant_management_endpoints.py: endpoint tests, including checking the change is still there after restarting the app.
  • Full suite passes (120). Also ran the server and checked create/update survive a real restart.

Lets routes return 404 and 409 without guessing from ValueError, which is already used for invalid data files.
Builds the full restaurant from the request (server sets id, type and no menu), rejects a duplicate name + address, and saves it.
Returns 201 with the new restaurant, 422 for invalid input and 409 for a duplicate. Tests check the restaurant is still there after a restart.
Changes only the fields that were sent, keeps the id, rejects an unknown id and an update that would duplicate another restaurant, then saves.
Returns the updated restaurant, 404 for an unknown id, 409 for a duplicate and 422 for invalid or empty input. Tests check the change is still there after a restart.
@sonoftirit sonoftirit added the enhancement New feature or request label Oct 16, 2026
@sonoftirit sonoftirit self-assigned this Oct 16, 2026
…update-restaurant

# Conflicts:
#	backend/app/services/restaurant_service.py

@CookieLynx CookieLynx 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.

Creation and modification of the restaurants are looking good!

Summary for the repsonses is a nice touch.

Good error handling!

Good tests!

overall looking good, approved!

@CookieLynx
CookieLynx merged commit 8024c90 into main Oct 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Create restaurant management endpoints [USER STORY] [US 2.2 Updating Restaurant Information] [USER STORY] [US 2.1 Creating Restaurant]

2 participants