This commit is contained in:
fengchuanhn@gmail.com
2026-05-21 01:47:21 +08:00
parent 7f57dfa9ed
commit 5ee6a57dd1
29 changed files with 794 additions and 18 deletions

View File

@@ -31,6 +31,9 @@ async def list_card_keys(
default="all",
description="筛选all 全部 / unused 未使用 / used 已激活",
),
username: str | None = Query(default=None, description="按激活用户名模糊筛选"),
oem_id: int | None = Query(default=None, description="按预分配 OEM 筛选"),
agent_id: int | None = Query(default=None, description="按预分配代理筛选"),
) -> ApiResponse[PaginatedData[CardKeyOut]]:
filter_status = None if status == "all" else status
cards, total = await card_key_service.list_card_keys(
@@ -38,6 +41,9 @@ async def list_card_keys(
page=page,
page_size=page_size,
status=filter_status,
username=username,
oem_id=oem_id,
agent_id=agent_id,
)
return ApiResponse(
ok=True,

View File

@@ -0,0 +1,49 @@
"""管理员:默认 OEMid=1软件品牌配置。"""
from fastapi import APIRouter
from app.dependencies import AdminUser, DbSession
from app.schemas.admin_oem_branding import OemBrandingOut, OemBrandingUpdate
from app.schemas.common import ApiResponse
from app.services import admin_oem_branding as branding_service
router = APIRouter(prefix="/admin/oem-branding", tags=["管理-OEM品牌"])
@router.get("", response_model=ApiResponse[OemBrandingOut])
async def get_oem_branding(
admin: AdminUser,
db: DbSession,
) -> ApiResponse[OemBrandingOut]:
try:
oem = await branding_service.get_default_oem_branding(
db, owner_user_id=admin.id
)
except branding_service.AdminOemBrandingError as exc:
return ApiResponse(ok=False, message=exc.message)
return ApiResponse(
ok=True,
message="",
data=OemBrandingOut.model_validate(oem),
)
@router.patch("", response_model=ApiResponse[OemBrandingOut])
async def update_oem_branding(
body: OemBrandingUpdate,
admin: AdminUser,
db: DbSession,
) -> ApiResponse[OemBrandingOut]:
try:
oem = await branding_service.update_default_oem_branding(
db, body, owner_user_id=admin.id
)
except branding_service.AdminOemBrandingError as exc:
return ApiResponse(ok=False, message=exc.message)
return ApiResponse(
ok=True,
message="软件配置已保存",
data=OemBrandingOut.model_validate(oem),
)

View File

@@ -21,8 +21,20 @@ async def list_users(
le=admin_user_service.MAX_PAGE_SIZE,
description="每页条数",
),
username: str | None = Query(None, description="用户名模糊搜索"),
oem_id: int | None = Query(None, description="按所属 OEM 用户 ID 筛选"),
agent_id: int | None = Query(None, description="按所属代理用户 ID 筛选"),
role_id: int | None = Query(None, ge=0, le=3, description="按角色筛选"),
) -> ApiResponse[PaginatedData[AdminUserOut]]:
users, total = await admin_user_service.list_users(db, page=page, page_size=page_size)
users, total = await admin_user_service.list_users(
db,
page=page,
page_size=page_size,
username=username,
oem_id=oem_id,
agent_id=agent_id,
role_id=role_id,
)
return ApiResponse(
ok=True,
message="",

19
app/api/v1/oem_public.py Normal file
View File

@@ -0,0 +1,19 @@
"""公开 OEM 品牌信息(无需鉴权)。"""
from fastapi import APIRouter, Path
from app.dependencies import DbSession
from app.schemas.common import ApiResponse
from app.schemas.oem_public import OemPublicBrandingOut
from app.services import oem_public as oem_public_service
router = APIRouter(prefix="/public/oem-branding", tags=["公开-OEM品牌"])
@router.get("/{oem_id}", response_model=ApiResponse[OemPublicBrandingOut])
async def get_oem_branding_public(
db: DbSession,
oem_id: int = Path(ge=1, description="OEM 记录 ID"),
) -> ApiResponse[OemPublicBrandingOut]:
data = await oem_public_service.get_oem_public_branding(db, oem_id)
return ApiResponse(ok=True, message="", data=data)

View File

@@ -3,18 +3,22 @@ from fastapi import APIRouter
from app.api.v1 import (
admin_card_keys,
admin_desktop_configs,
admin_oem_branding,
admin_users,
app_config,
oem_public,
auth,
nodejs_scripts,
quickjs_scripts,
)
api_router = APIRouter()
api_router.include_router(oem_public.router)
api_router.include_router(auth.router)
api_router.include_router(admin_users.router)
api_router.include_router(admin_card_keys.router)
api_router.include_router(admin_desktop_configs.router)
api_router.include_router(admin_oem_branding.router)
api_router.include_router(app_config.router)
api_router.include_router(quickjs_scripts.router)
api_router.include_router(nodejs_scripts.router)