64 lines
1.3 KiB
Markdown
64 lines
1.3 KiB
Markdown
# Lunch Picker Backend
|
|
|
|
Express API server for Lunch Picker miniapp.
|
|
|
|
## Modes
|
|
|
|
- Memory mode: run without MySQL env vars (quick local demo)
|
|
- MySQL mode: set `MYSQL_HOST` (or `MYSQL_URL`) and run with real DB
|
|
|
|
## 1) Install
|
|
|
|
```bash
|
|
cd backend
|
|
npm install
|
|
cp .env.example .env
|
|
```
|
|
|
|
## 2) Start
|
|
|
|
```bash
|
|
npm start
|
|
```
|
|
|
|
Server: `http://localhost:4000`
|
|
|
|
## 3) MySQL setup
|
|
|
|
1. Create DB (example)
|
|
|
|
```sql
|
|
create database lunch_picker character set utf8mb4 collate utf8mb4_0900_ai_ci;
|
|
```
|
|
|
|
2. Apply schema
|
|
|
|
```bash
|
|
mysql -u root -p lunch_picker < ../docs/db/schema.sql
|
|
```
|
|
|
|
3. Set `.env` values (`MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE`)
|
|
|
|
When MySQL mode starts, seed data is inserted automatically only when `restaurant` table is empty.
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /v1/health`
|
|
- `GET /v1/restaurants/nearby`
|
|
- `GET /v1/restaurants/:restaurantId`
|
|
- `GET /v1/restaurants/:restaurantId/reviews`
|
|
- `POST /v1/restaurants/:restaurantId/reviews`
|
|
- `DELETE /v1/reviews/:reviewId`
|
|
- `POST /v1/restaurants/:restaurantId/like`
|
|
- `GET /v1/users/me/reviews`
|
|
|
|
## Auth Simulation
|
|
|
|
Set `x-user-id` header to simulate user identity.
|
|
|
|
Example:
|
|
|
|
```bash
|
|
curl -H "x-user-id: demo-user-1" "http://localhost:4000/v1/restaurants/nearby?lat=37.501&lng=127.037&radiusMeters=1000&sort=distance"
|
|
```
|