mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 12:19:06 +00:00
Zulip auto post
This commit is contained in:
@@ -68,6 +68,9 @@ class RoomController:
|
||||
self,
|
||||
name: str,
|
||||
user_id: str,
|
||||
zulip_auto_post: bool,
|
||||
zulip_stream: str,
|
||||
zulip_topic: str,
|
||||
):
|
||||
"""
|
||||
Add a new room
|
||||
@@ -75,11 +78,24 @@ class RoomController:
|
||||
room = Room(
|
||||
name=name,
|
||||
user_id=user_id,
|
||||
zulip_auto_post=zulip_auto_post,
|
||||
zulip_stream=zulip_stream,
|
||||
zulip_topic=zulip_topic,
|
||||
)
|
||||
query = rooms.insert().values(**room.model_dump())
|
||||
await database.execute(query)
|
||||
return room
|
||||
|
||||
async def update(self, room: Room, values: dict, mutate=True):
|
||||
"""
|
||||
Update a room fields with key/values in values
|
||||
"""
|
||||
query = rooms.update().where(rooms.c.id == room.id).values(**values)
|
||||
await database.execute(query)
|
||||
if mutate:
|
||||
for key, value in values.items():
|
||||
setattr(room, key, value)
|
||||
|
||||
async def get_by_id(self, room_id: str, **kwargs) -> Room | None:
|
||||
"""
|
||||
Get a room by id
|
||||
|
||||
@@ -21,6 +21,9 @@ class Room(BaseModel):
|
||||
name: str
|
||||
user_id: str
|
||||
created_at: datetime
|
||||
zulip_auto_post: bool
|
||||
zulip_stream: str
|
||||
zulip_topic: str
|
||||
|
||||
|
||||
class Meeting(BaseModel):
|
||||
@@ -35,6 +38,16 @@ class Meeting(BaseModel):
|
||||
|
||||
class CreateRoom(BaseModel):
|
||||
name: str
|
||||
zulip_auto_post: bool
|
||||
zulip_stream: str
|
||||
zulip_topic: str
|
||||
|
||||
|
||||
class UpdateRoom(BaseModel):
|
||||
name: str
|
||||
zulip_auto_post: bool
|
||||
zulip_stream: str
|
||||
zulip_topic: str
|
||||
|
||||
|
||||
class DeletionStatus(BaseModel):
|
||||
@@ -69,9 +82,27 @@ async def rooms_create(
|
||||
return await rooms_controller.add(
|
||||
name=room.name,
|
||||
user_id=user_id,
|
||||
zulip_auto_post=room.zulip_auto_post,
|
||||
zulip_stream=room.zulip_stream,
|
||||
zulip_topic=room.zulip_topic,
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/rooms/{room_id}", response_model=Room)
|
||||
async def rooms_update(
|
||||
room_id: str,
|
||||
info: UpdateRoom,
|
||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
||||
):
|
||||
user_id = user["sub"] if user else None
|
||||
room = await rooms_controller.get_by_id_for_http(room_id, user_id=user_id)
|
||||
if not room:
|
||||
raise HTTPException(status_code=404, detail="Room not found")
|
||||
values = info.dict(exclude_unset=True)
|
||||
await rooms_controller.update(room, values)
|
||||
return room
|
||||
|
||||
|
||||
@router.delete("/rooms/{room_id}", response_model=DeletionStatus)
|
||||
async def rooms_delete(
|
||||
room_id: str,
|
||||
|
||||
Reference in New Issue
Block a user