Add benchmark & tier-offset configuration UI to Direct Rates Manage tab
- new GET /direct/hotels/{id}/config returns full hotel config plus
distinct room/rate IDs from scraped data (and any known via labels)
- Configure panel: benchmark room/rate selects, tier base room, per-room
£ offsets (base locked to 0), friendly room/rate names, room display
order (up/down) — saved via the existing PUT endpoint
- enables apples-to-apples estimated benchmark when only e.g. a suite
is left: bench = room_price - room_offset + bench_offset
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
46020576f8
commit
029e3b379f
2 changed files with 309 additions and 2 deletions
|
|
@ -177,6 +177,46 @@ async def delete_hotel(hotel_id: int, user=Depends(get_current_user)):
|
|||
await db.commit()
|
||||
|
||||
|
||||
@router.get("/hotels/{hotel_id}/config")
|
||||
async def hotel_config(hotel_id: int, user=Depends(get_current_user)):
|
||||
"""Full config for one hotel plus the room/rate IDs seen in scraped data,
|
||||
for the benchmark / tier-offset / label configuration UI."""
|
||||
require_cap(user, "manage_hotels")
|
||||
async with AsyncSessionLocal() as db:
|
||||
cfg_row = await db.execute(
|
||||
text("""SELECT id, name, profile_name, params, room_labels, rate_labels,
|
||||
room_order, benchmark_room, benchmark_rate, tier_base_room,
|
||||
tier_offsets, scrape_enabled
|
||||
FROM direct_competitor_hotels WHERE id = :id"""),
|
||||
{"id": hotel_id}
|
||||
)
|
||||
hotel = cfg_row.mappings().fetchone()
|
||||
if not hotel:
|
||||
raise HTTPException(status_code=404, detail="Hotel not found")
|
||||
|
||||
ids_result = await db.execute(
|
||||
text("""SELECT DISTINCT room_id, rate_id FROM direct_rates
|
||||
WHERE hotel_id = :hid"""),
|
||||
{"hid": hotel_id}
|
||||
)
|
||||
pairs = ids_result.fetchall()
|
||||
|
||||
room_ids = sorted({p[0] for p in pairs})
|
||||
rate_ids = sorted({p[1] for p in pairs})
|
||||
# Include any rooms known only from labels/order (e.g. discovery without a scrape yet)
|
||||
for rid in (hotel["room_labels"] or {}):
|
||||
if rid not in room_ids:
|
||||
room_ids.append(rid)
|
||||
for rid in (hotel["rate_labels"] or {}):
|
||||
if rid not in rate_ids:
|
||||
rate_ids.append(rid)
|
||||
|
||||
out = dict(hotel)
|
||||
out["room_ids"] = room_ids
|
||||
out["rate_ids"] = rate_ids
|
||||
return out
|
||||
|
||||
|
||||
# ─── Discovery ───────────────────────────────────────────────────────────────
|
||||
|
||||
@router.post("/hotels/{hotel_id}/discover")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue