change to get

This commit is contained in:
Jeremy Yin 2024-03-15 22:45:53 +08:00
parent cec5266655
commit 605f84688e
2 changed files with 7 additions and 7 deletions

View File

@ -83,15 +83,15 @@ async def get_ai_chat_response(request: Request, req: GetAiChatResponseInput) ->
return res
@app.post("/api/v1/get_user_chat_history")
async def get_user_chat_history(request: Request, req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput:
@app.get("/api/v1/get_user_chat_history")
async def get_user_chat_history(request: Request, user_name: str, last_n: int) -> GetUserChatHistoryOutput:
pvd = Providers(db=request.app.db)
user = await pvd.user.get_user_by_name(req.user_name)
user = await pvd.user.get_user_by_name(user_name)
if not user:
raise UserNotFoundError(req.user_name)
raise UserNotFoundError(user_name)
ctx = Context(user=user)
svc = Services(ctx, pvd)
res = await svc.chat.get_user_chat_history(req)
res = await svc.chat.get_user_chat_history(last_n=last_n)
return res

View File

@ -40,8 +40,8 @@ class ChatService:
res = GetAiChatResponseOutput(response=response_content)
return res
async def get_user_chat_history(self, req: GetUserChatHistoryInput) -> GetUserChatHistoryOutput:
messages = await self.pvd.chat.get_user_chat_messages(user_id=self.ctx.user.id, limit=req.last_n)
async def get_user_chat_history(self, last_n: int) -> GetUserChatHistoryOutput:
messages = await self.pvd.chat.get_user_chat_messages(user_id=self.ctx.user.id, limit=last_n)
res = []
for message in messages:
res.append(UserChatMessage(type=message.type.value, text=message.text))