init: 初始化项目

This commit is contained in:
zwt13703
2026-07-08 20:02:29 +08:00
parent 22590ae7b8
commit 1bb84df4ca
98 changed files with 8535 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from app.core.database import get_db
from app.models.system_config import SystemConfig
router = APIRouter(prefix="/settings", tags=["系统设置"])
@router.get("")
async def get_all_settings(db: AsyncSession = Depends(get_db)):
result = await db.execute(select(SystemConfig))
configs = result.scalars().all()
return {c.key: c.value for c in configs}
@router.put("/{key}")
async def update_setting(key: str, body: dict, db: AsyncSession = Depends(get_db)):
result = await db.execute(select(SystemConfig).where(SystemConfig.key == key))
config = result.scalar_one_or_none()
value = body.get("value", "")
description = body.get("description", "")
if config:
config.value = value
if description:
config.description = description
else:
config = SystemConfig(key=key, value=value, description=description)
db.add(config)
await db.flush()
return {"key": key, "value": value}