update_260202-3

This commit is contained in:
lusixing
2026-02-02 22:22:11 -08:00
parent 106c3421e6
commit 9cbd3347f6
9 changed files with 125 additions and 6 deletions

View File

@@ -99,9 +99,18 @@ async def get_my_assets(
db: AsyncSession = Depends(database.get_db)
):
result = await db.execute(
select(models.Asset).where(models.Asset.author_id == current_user.id)
select(models.Asset)
.options(selectinload(models.Asset.heir))
.where(models.Asset.author_id == current_user.id)
)
return result.scalars().all()
assets = result.scalars().all()
# Populate heir_email for the schema
for asset in assets:
if asset.heir:
asset.heir_email = asset.heir.email
else:
asset.heir_email = None
return assets
@app.post("/assets/create", response_model=schemas.AssetOut)
@@ -235,6 +244,30 @@ async def get_designated_assets(
)
return result.scalars().all()
@app.post("/assets/delete")
async def delete_asset(
asset_del: schemas.AssetDelete,
current_user: models.User = Depends(auth.get_current_user),
db: AsyncSession = Depends(database.get_db)
):
"""
Delete an asset owned by the current user.
"""
result = await db.execute(
select(models.Asset).where(models.Asset.id == asset_del.asset_id)
)
asset = result.scalars().first()
if not asset:
raise HTTPException(status_code=404, detail="Asset not found")
if asset.author_id != current_user.id:
raise HTTPException(status_code=403, detail="Not authorized to delete this asset")
await db.delete(asset)
await db.commit()
return {"message": "Asset deleted successfully"}
@app.get("/users/search", response_model=List[schemas.UserOut])
async def search_users(
query: str,
@@ -416,6 +449,17 @@ async def ai_proxy(
detail=f"An error occurred while requesting AI provider: {str(e)}"
)
@app.get("/get_ai_roles", response_model=List[schemas.AIRoleOut])
async def get_ai_roles(
current_user: models.User = Depends(auth.get_current_user),
db: AsyncSession = Depends(database.get_db)
):
"""
Get all available AI roles for the logged-in user.
"""
result = await db.execute(select(models.AIRole).order_by(models.AIRole.id))
return result.scalars().all()
# 用于测试热加载
@app.post("/post1")
async def test1():