This commit is contained in:
Timothy Jaeryang Baek
2024-12-22 22:20:24 -07:00
parent 5748f6ef77
commit a4333295ce
4 changed files with 80 additions and 13 deletions

View File

@@ -69,11 +69,11 @@ class ChannelTable:
with get_db() as db:
channel = ChannelModel(
**{
**form_data.dict(),
**form_data.model_dump(),
"id": str(uuid.uuid4()),
"user_id": user_id,
"created_at": int(time.time()),
"updated_at": int(time.time()),
"created_at": int(time.time_ns()),
"updated_at": int(time.time_ns()),
}
)
@@ -116,7 +116,7 @@ class ChannelTable:
channel.data = form_data.data
channel.meta = form_data.meta
channel.access_control = form_data.access_control
channel.updated_at = int(time.time())
channel.updated_at = int(time.time_ns())
db.commit()
return ChannelModel.model_validate(channel) if channel else None

View File

@@ -57,6 +57,27 @@ async def create_new_channel(form_data: ChannelForm, user=Depends(get_admin_user
)
############################
# GetChannelById
############################
@router.get("/{id}", response_model=Optional[ChannelModel])
async def get_channel_by_id(id: str, user=Depends(get_verified_user)):
channel = Channels.get_channel_by_id(id)
if not channel:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
)
if not has_access(user.id, type="read", access_control=channel.access_control):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT()
)
return ChannelModel(**channel.model_dump())
############################
# GetChannelMessages
############################