fix bug authen
Browse files- app/itineraries/__init__.py +1 -1
- app/itineraries/router.py +27 -14
app/itineraries/__init__.py
CHANGED
|
@@ -17,7 +17,7 @@ class StopBase(BaseModel):
|
|
| 17 |
|
| 18 |
class StopCreate(StopBase):
|
| 19 |
"""Create stop request."""
|
| 20 |
-
|
| 21 |
|
| 22 |
|
| 23 |
class StopUpdate(BaseModel):
|
|
|
|
| 17 |
|
| 18 |
class StopCreate(StopBase):
|
| 19 |
"""Create stop request."""
|
| 20 |
+
snapshot: dict | None = Field(None, description="Place snapshot (name, category, etc.) - optional, will be fetched from DB if not provided")
|
| 21 |
|
| 22 |
|
| 23 |
class StopUpdate(BaseModel):
|
app/itineraries/router.py
CHANGED
|
@@ -44,6 +44,16 @@ async def create_itinerary(
|
|
| 44 |
# Validate user_id is a valid UUID
|
| 45 |
validate_uuid(user_id, "user_id")
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
result = await db.execute(
|
| 48 |
text("""
|
| 49 |
INSERT INTO itineraries (user_id, title, start_date, end_date, total_days, total_budget, currency)
|
|
@@ -323,20 +333,23 @@ async def add_stop(
|
|
| 323 |
if not check.fetchone():
|
| 324 |
raise HTTPException(status_code=404, detail="Itinerary not found")
|
| 325 |
|
| 326 |
-
# Get place snapshot
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
# Insert stop
|
| 342 |
result = await db.execute(
|
|
|
|
| 44 |
# Validate user_id is a valid UUID
|
| 45 |
validate_uuid(user_id, "user_id")
|
| 46 |
|
| 47 |
+
# Ensure profile exists (auto-create if needed for demo purposes)
|
| 48 |
+
await db.execute(
|
| 49 |
+
text("""
|
| 50 |
+
INSERT INTO profiles (id, full_name, role, locale)
|
| 51 |
+
VALUES (:user_id, 'Anonymous User', 'tourist', 'vi_VN')
|
| 52 |
+
ON CONFLICT (id) DO NOTHING
|
| 53 |
+
"""),
|
| 54 |
+
{"user_id": user_id}
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
result = await db.execute(
|
| 58 |
text("""
|
| 59 |
INSERT INTO itineraries (user_id, title, start_date, end_date, total_days, total_budget, currency)
|
|
|
|
| 333 |
if not check.fetchone():
|
| 334 |
raise HTTPException(status_code=404, detail="Itinerary not found")
|
| 335 |
|
| 336 |
+
# Get place snapshot - prefer from request, otherwise from DB
|
| 337 |
+
snapshot = request.snapshot
|
| 338 |
+
if not snapshot:
|
| 339 |
+
# Try to fetch from database
|
| 340 |
+
place_result = await db.execute(
|
| 341 |
+
text("SELECT name, category, address, rating FROM places_metadata WHERE place_id = :place_id"),
|
| 342 |
+
{"place_id": request.place_id}
|
| 343 |
+
)
|
| 344 |
+
place_row = place_result.fetchone()
|
| 345 |
+
if place_row:
|
| 346 |
+
snapshot = {
|
| 347 |
+
"name": place_row.name,
|
| 348 |
+
"category": place_row.category,
|
| 349 |
+
"address": place_row.address,
|
| 350 |
+
"rating": float(place_row.rating) if place_row.rating else None,
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
|
| 354 |
# Insert stop
|
| 355 |
result = await db.execute(
|