This commit is contained in:
fengchuanhn@gmail.com
2026-05-21 16:38:11 +08:00
parent 8d5f5f2608
commit 13c8493e4c
8 changed files with 116 additions and 14 deletions

View File

@@ -44,11 +44,21 @@ async def list_configs(
async def create_config(db: AsyncSession, body: DesktopConfigCreate) -> DesktopConfig:
existing = await db.scalar(select(DesktopConfig).where(DesktopConfig.name == body.name))
existing = await db.scalar(
select(DesktopConfig).where(
DesktopConfig.name == body.name,
DesktopConfig.oem_id == body.oem_id,
)
)
if existing is not None:
raise AdminDesktopConfigError("配置键名已存在")
raise AdminDesktopConfigError("该 OEM 下配置键名已存在")
row = DesktopConfig(name=body.name, value=body.value, mark=body.mark)
row = DesktopConfig(
name=body.name,
value=body.value,
mark=body.mark,
oem_id=body.oem_id,
)
db.add(row)
await db.flush()
await db.refresh(row)
@@ -65,9 +75,15 @@ async def update_config(
raise AdminDesktopConfigError("配置不存在")
if body.name is not None and body.name != row.name:
taken = await db.scalar(select(DesktopConfig).where(DesktopConfig.name == body.name))
taken = await db.scalar(
select(DesktopConfig).where(
DesktopConfig.name == body.name,
DesktopConfig.oem_id == row.oem_id,
DesktopConfig.id != config_id,
)
)
if taken is not None:
raise AdminDesktopConfigError("配置键名已存在")
raise AdminDesktopConfigError("该 OEM 下配置键名已存在")
row.name = body.name
if body.value is not None: