转移
This commit is contained in:
19
routers/user.py
Normal file
19
routers/user.py
Normal 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 }
|
||||
|
Reference in New Issue
Block a user