|
|
@@ -1,8 +1,9 @@
|
|
|
from typing import Annotated
|
|
|
-from fastapi import APIRouter, Depends, HTTPException, Path
|
|
|
+from fastapi import APIRouter, Depends, Path
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
|
+from app.core.router_class import OperationLogRoute
|
|
|
from app.plugin.module_payment.apikey.schema import (
|
|
|
TenantApiKeyCreate,
|
|
|
TenantApiKeyResponse,
|
|
|
@@ -11,12 +12,12 @@ from app.plugin.module_payment.apikey.schema import (
|
|
|
ApiKeyQueryParam,
|
|
|
)
|
|
|
from app.plugin.module_payment.apikey.service import TenantApiKeyService
|
|
|
-from app.common.response import ResponseSchema, SuccessResponse
|
|
|
+from app.common.response import ResponseSchema, SuccessResponse, ErrorResponse
|
|
|
from app.core.base_params import PaginationQueryParam
|
|
|
from app.core.dependencies import AuthPermission
|
|
|
from app.core.logger import log
|
|
|
|
|
|
-ApiKeyRouter = APIRouter(prefix="/api-key", tags=["租户API Key管理"])
|
|
|
+ApiKeyRouter = APIRouter(route_class=OperationLogRoute, prefix="/api-key", tags=["API Key管理"])
|
|
|
|
|
|
|
|
|
@ApiKeyRouter.post(
|
|
|
@@ -29,7 +30,7 @@ async def create_api_key_controller(
|
|
|
data: TenantApiKeyCreate,
|
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:tenant:api-key:create"]))],
|
|
|
) -> JSONResponse:
|
|
|
- tenant_id = data.tenant_id or auth.tenant_id
|
|
|
+ tenant_id = auth.tenant_id
|
|
|
api_key_obj = await TenantApiKeyService.create_api_key(
|
|
|
auth=auth,
|
|
|
tenant_id=tenant_id,
|
|
|
@@ -45,7 +46,8 @@ async def create_api_key_controller(
|
|
|
status=api_key_obj.status,
|
|
|
expired_at=api_key_obj.expired_at,
|
|
|
created_time=api_key_obj.created_time,
|
|
|
- )
|
|
|
+ ),
|
|
|
+ msg="创建APIKey成功"
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -60,15 +62,12 @@ async def get_api_key_list_controller(
|
|
|
search: Annotated[ApiKeyQueryParam, Depends()],
|
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:tenant:api-key:query"]))],
|
|
|
) -> JSONResponse:
|
|
|
- target_tenant_id = search.tenant_id or auth.tenant_id
|
|
|
result_dict = await TenantApiKeyService.get_api_key_page_service(
|
|
|
auth=auth,
|
|
|
page_no=page.page_no,
|
|
|
page_size=page.page_size,
|
|
|
- tenant_id=target_tenant_id,
|
|
|
- status=search.status,
|
|
|
+ search=search
|
|
|
)
|
|
|
- log.info("查询API Key成功")
|
|
|
return SuccessResponse(data=result_dict)
|
|
|
|
|
|
|
|
|
@@ -83,21 +82,7 @@ async def update_api_key_status_controller(
|
|
|
data: TenantApiKeyUpdate,
|
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:tenant:api-key:update"]))],
|
|
|
) -> JSONResponse:
|
|
|
- api_key_obj = await TenantApiKeyService.update_api_key_status(auth=auth, api_key_id=api_key_id, status=data.status)
|
|
|
- if not api_key_obj:
|
|
|
- raise HTTPException(status_code=404, detail="API Key不存在")
|
|
|
- log.info(f"更新API Key状态成功: ID={api_key_id}, 状态={data.status}")
|
|
|
- return SuccessResponse(
|
|
|
- data=TenantApiKeyListResponse(
|
|
|
- id=api_key_obj.id,
|
|
|
- api_key=api_key_obj.api_key,
|
|
|
- status=api_key_obj.status,
|
|
|
- expired_at=api_key_obj.expired_at,
|
|
|
- last_used_at=api_key_obj.last_used_at,
|
|
|
- created_time=api_key_obj.created_time,
|
|
|
- description=api_key_obj.description,
|
|
|
- )
|
|
|
- )
|
|
|
+ return ErrorResponse(msg="暂不支持操作")
|
|
|
|
|
|
|
|
|
@ApiKeyRouter.delete(
|
|
|
@@ -110,8 +95,6 @@ async def delete_api_key_controller(
|
|
|
api_key_id: Annotated[int, Path(description="API Key ID")],
|
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:tenant:api-key:delete"]))],
|
|
|
) -> JSONResponse:
|
|
|
- success = await TenantApiKeyService.delete_api_key(auth=auth, api_key_id=api_key_id)
|
|
|
- if not success:
|
|
|
- raise HTTPException(status_code=404, detail="API Key不存在")
|
|
|
+ await TenantApiKeyService.delete_api_key(auth=auth, api_key_id=api_key_id)
|
|
|
log.info(f"删除API Key成功: ID={api_key_id}")
|
|
|
- return SuccessResponse(data={"success": True})
|
|
|
+ return SuccessResponse(msg="删除APIKey成功")
|