This commit is contained in:
2024-11-04 05:20:42 +08:00
parent e990473dcd
commit 07de4d5fd5
24 changed files with 1385 additions and 2 deletions

19
routers/user.py Normal file
View File

@@ -0,0 +1,19 @@
from fastapi import APIRouter, HTTPException
from models.mysql import conn, get_cursor
router = APIRouter()
@router.get('/{user_id}/collect', summary="用户收藏记录", description="获取指定用户收藏记录")
def get_user_collect(user_id:int):
# TODO: 需要验证权限
cursor = get_cursor()
cursor.execute(f"SELECT content FROM web_collect WHERE user_id={user_id} AND type='1'")
data = cursor.fetchall()
if not data:
return {'code': 0, 'user_id': user_id, 'total': 0, 'data': []}
data = [str(item['content']) for item in data]
cursor.execute(f"SELECT id FROM web_images WHERE content IN ({','.join(['%s'] * len(data))})", data)
data = cursor.fetchall()
data = [str(item['id']) for item in data]
return {'code': 0, 'user_id': user_id, 'total': len(data), 'data': data }