Skip to content

created API for restaurants - #2

Merged
prepwave merged 3 commits into
mainfrom
development
Jul 18, 2026
Merged

created API for restaurants#2
prepwave merged 3 commits into
mainfrom
development

Conversation

@prepwave

@prepwave prepwave commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Introduced restaurant discovery API with search, cuisine, price range, featured flag, and pagination/sorting.
    • Added featured restaurant and slug-based restaurant lookups.
    • Added booking availability lookup by date, returning pending/confirmed bookings sorted by time slot.
    • Added booking data support with validated guest counts and booking status tracking.
    • Exposed new restaurant endpoints under /api/restaurants.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b090fe2b-c56f-4721-9484-c67f52c5739f

📥 Commits

Reviewing files that changed from the base of the PR and between fffd0e6 and e6bf12f.

📒 Files selected for processing (1)
  • server/controllers/restaurantController.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/controllers/restaurantController.ts

📝 Walkthrough

Walkthrough

Adds restaurant and booking Mongoose models, four restaurant read handlers, Express routes for listings, featured restaurants, slug lookup, and date-filtered bookings, and mounts them under /api/restaurants.

Changes

Restaurant API

Layer / File(s) Summary
Restaurant and booking data models
server/models/Restaurants.ts, server/models/Booking.ts
Defines typed Mongoose schemas with validation, defaults, references, timestamps, indexes, and model exports.
Restaurant read controllers
server/controllers/restaurantController.ts
Adds filtered and paginated restaurant listing, featured restaurant retrieval, slug lookup, and date-filtered booking handlers.
Route integration
server/routes/restaurant.routes.ts, server/server.ts
Registers four GET routes and mounts the router at /api/restaurants.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant restaurantRouter
  participant restaurantController
  participant MongoDB
  Client->>restaurantRouter: GET /api/restaurants endpoint
  restaurantRouter->>restaurantController: Invoke matched handler
  restaurantController->>MongoDB: Query restaurants or bookings
  MongoDB-->>restaurantController: Return matching documents
  restaurantController-->>Client: Return JSON response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is relevant and accurately describes the main change: adding restaurant API endpoints and related models.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch development

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/controllers/restaurantController.ts`:
- Around line 49-50: Update the Restaurant.find query in the listing flow and
the corresponding slug endpoint populate calls to exclude the owner email,
returning only explicitly public owner fields such as name. Keep the owner
relationship populated while removing email from both public restaurant read
responses.
- Around line 27-31: Update the search handling in the restaurant query
construction to escape all regex metacharacters in the user-provided search
value and truncate or reject inputs exceeding a short maximum length before
assigning query.name.$regex. Preserve case-insensitive matching while ensuring
the resulting MongoDB regex is bounded and safe.
- Around line 46-53: Validate the page and limit inputs before the
Restaurant.find pagination chain: require finite positive integers, apply a
reasonable maximum cap to limit, and use safe fallback values for invalid
inputs. Pass only the validated page and capped limit to skip() and limit().
- Around line 155-180: Update the date handling before the Booking.find query to
require an exact YYYY-MM-DD value and reject malformed or calendar-invalid dates
with the existing 400 response. Construct the day range in UTC, using UTC
midnight as the inclusive start and the following UTC midnight as an exclusive
upper bound; update the bookingDate filter accordingly.

In `@server/models/Booking.ts`:
- Around line 10-12: Rename the misspelled cccasion property to occasion in the
Booking model and add the corresponding occasion field to BookingSchema,
preserving its optional string type so values accepted by TypeScript are
retained by Mongoose.

In `@server/routes/restaurant.routes.ts`:
- Around line 17-18: Update the getRestaurantBookings route and its handler to
require restaurant-owner or admin authorization before returning booking
records; alternatively, restrict the response to non-identifying slot
availability and omit reservation status and populated customer names or emails.
Ensure arbitrary restaurant IDs cannot expose protected booking data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ba18423-684e-486f-a03a-6d8f7ea0b5e7

📥 Commits

Reviewing files that changed from the base of the PR and between 1c9aac7 and fffd0e6.

📒 Files selected for processing (5)
  • server/controllers/restaurantController.ts
  • server/models/Booking.ts
  • server/models/Restaurants.ts
  • server/routes/restaurant.routes.ts
  • server/server.ts

Comment thread server/controllers/restaurantController.ts
Comment thread server/controllers/restaurantController.ts
Comment thread server/controllers/restaurantController.ts
Comment thread server/controllers/restaurantController.ts
Comment thread server/models/Booking.ts
Comment thread server/routes/restaurant.routes.ts
@prepwave
prepwave merged commit d9fe2f4 into main Jul 18, 2026
1 check passed
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.

1 participant