From 0631edf8a27b4f7cf037f914932c57515392438c Mon Sep 17 00:00:00 2001 From: Padreug Date: Mon, 20 Jul 2026 01:39:39 +0200 Subject: [PATCH] feat: public guest room discovery endpoints (slice 1 for webapp #141) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GET /public/rooms + /public/rooms/{id} — no auth, active rooms only, operator-private fields stripped. The webapp guest UI needs these because the existing GET /rooms is admin-scoped; availability + booking POST are already public. Reuses the public_room_dict strip. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_019VUQCfdqiLSsFS2jcGnaFD --- views_api.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/views_api.py b/views_api.py index 1f24a87..7b28cde 100644 --- a/views_api.py +++ b/views_api.py @@ -24,6 +24,7 @@ from .models import ( CreateRoomData, Room, RoomStatus, + public_room_dict, ) from .nostr import service as nostr @@ -189,6 +190,27 @@ async def api_update_settings( return await crud.update_settings(settings) +# --- public guest discovery (no auth) -------------------------------------- + + +@chatelet_api_router.get("/api/v1/public/rooms") +async def api_public_rooms() -> list[dict]: + """Active rooms for guest browsing — operator-private fields stripped.""" + return [ + public_room_dict(r) + for r in await crud.get_rooms() + if r.status == RoomStatus.active + ] + + +@chatelet_api_router.get("/api/v1/public/rooms/{room_id}") +async def api_public_room(room_id: str) -> dict: + room = await crud.get_room(room_id) + if not room or room.status != RoomStatus.active: + raise HTTPException(404, "Room not available") + return public_room_dict(room) + + # --- availability (public read) --------------------------------------------