This commit is contained in:
Lilian 2023-02-28 11:56:04 +01:00 committed by Kilton937342
parent 2119973dbb
commit 970a4b200b

View File

@ -1,24 +0,0 @@
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)