feat(room): 添加删除房间功能
- 实现了删除房间的 API 接口 - 删除房间时,同时从 Redis 和数据库中移除相关数据
This commit is contained in:
@@ -93,3 +93,14 @@ async def create_room(
|
|||||||
return APICreatedRoom(**room.model_dump(), error=None)
|
return APICreatedRoom(**room.model_dump(), error=None)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=500, detail="redis error")
|
raise HTTPException(status_code=500, detail="redis error")
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/rooms/{room}", tags=["room"])
|
||||||
|
async def remove_room(room: int, db: AsyncSession = Depends(get_db)):
|
||||||
|
redis = get_redis()
|
||||||
|
if redis:
|
||||||
|
redis.delete(str(room))
|
||||||
|
room_index = await db.get(RoomIndex, room)
|
||||||
|
if room_index:
|
||||||
|
await db.delete(room_index)
|
||||||
|
await db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user