from fastapi import APIRouter, Depends from services.auth import get_current_user_optional from database.rooms.crud import create_room_with_user_db, create_room_anonymous_db, get_room_db from schemas.rooms import AnonymousIn_schema, RoomIn_schema, Room_schema from database.auth.models import User router = APIRouter() @router.post('/rooms', response_model=Room_schema) async def create_room(roomData: RoomIn_schema, anonymous: AnonymousIn_schema = None, user: User = Depends(get_current_user_optional)): if user is not None: room = await create_room_with_user_db(room=roomData, user=user) return await Room_schema.from_tortoise_orm(room) else: room = await create_room_anonymous_db(room=roomData, anonymous=anonymous) return await Room_schema.from_tortoise_orm(room) @router.get('/room/{room_id}') async def get_room(room_id: str): room = await get_room_db(room_id) if room is None: return None return await Room_schema.from_tortoise_orm(room)