| from typing import Optional |
|
|
| from fastapi import Query |
|
|
| from cbh.api.chat import chat_router |
| from cbh.api.chat.db_requests import get_all_chats_obj, create_chat_obj |
| from cbh.api.chat.dto import Paging |
| from cbh.api.chat.model import ChatModel |
| from cbh.api.chat.schemas import AllChatWrapper, AllChatResponse |
| from cbh.core.wrappers import CbhResponseWrapper |
|
|
|
|
| @chat_router.get('/all', response_model_by_alias=False, response_model=AllChatWrapper) |
| async def get_all_chats( |
| pageSize: Optional[int] = Query(10, description="Number of objects to return per page"), |
| pageIndex: Optional[int] = Query(0, description="Page index to retrieve"), |
| ): |
| chats, total_count = await get_all_chats_obj(pageSize, pageIndex) |
| response = AllChatResponse( |
| paging=Paging(pageSize=pageSize, pageIndex=pageIndex, totalCount=total_count), |
| data=chats |
| ) |
| return AllChatWrapper(data=response) |
|
|
|
|
| @chat_router.post('', response_model_by_alias=False, response_model=CbhResponseWrapper[ChatModel]) |
| async def create_chat(): |
| chat = await create_chat_obj() |
| return CbhResponseWrapper(data=chat) |
|
|