This commit is contained in:
aaron 2025-04-13 00:45:11 +08:00
parent 62fe13c5e8
commit 3823af638d

View File

@ -61,12 +61,16 @@ async def get_clothing(db: AsyncSession, clothing_id: int):
result = await db.execute(select(Clothing).filter(Clothing.id == clothing_id)) result = await db.execute(select(Clothing).filter(Clothing.id == clothing_id))
return result.scalars().first() return result.scalars().first()
async def get_clothes(db: AsyncSession, skip: int = 0, limit: int = 100, user_id: int = None): async def get_clothes(db: AsyncSession, skip: int = 0, limit: int = 100, user_id: int = None, category_id: int = None):
"""获取所有衣服""" """获取所有衣服"""
query = select(Clothing).order_by(Clothing.create_time.desc())
if user_id:
query = query.filter(Clothing.user_id == user_id)
if category_id:
query = query.filter(Clothing.clothing_category_id == category_id)
result = await db.execute( result = await db.execute(
select(Clothing) query
.filter(Clothing.user_id == user_id)
.order_by(Clothing.create_time.desc())
.offset(skip) .offset(skip)
.limit(limit) .limit(limit)
) )