20 lines
909 B
Python
20 lines
909 B
Python
from fastapi import APIRouter, HTTPException
|
|
from models.mysql import pool
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get('/{user_id}/collect', summary="用户收藏记录", description="获取指定用户收藏记录")
|
|
def get_user_collect(user_id:int):
|
|
with pool.connection() as conn:
|
|
with conn.cursor() as 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 }
|
|
|