Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return schema of the config api #551

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/app/admin/api/v1/sys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@router.get('/website', summary='获取网站配置信息', dependencies=[DependsJwtAuth])
async def get_website_config() -> ResponseSchemaModel[GetConfigDetail]:
async def get_website_config() -> ResponseSchemaModel[list[GetConfigDetail]]:
config = await config_service.get_built_in_config('website')
return response_base.success(data=config)

Expand All @@ -41,7 +41,7 @@ async def save_website_config(objs: list[SaveBuiltInConfigParam]) -> ResponseMod


@router.get('/protocol', summary='获取用户协议', dependencies=[DependsJwtAuth])
async def get_protocol_config() -> ResponseSchemaModel[GetConfigDetail]:
async def get_protocol_config() -> ResponseSchemaModel[list[GetConfigDetail]]:
config = await config_service.get_built_in_config('protocol')
return response_base.success(data=config)

Expand All @@ -60,7 +60,7 @@ async def save_protocol_config(objs: list[SaveBuiltInConfigParam]) -> ResponseMo


@router.get('/policy', summary='获取用户政策', dependencies=[DependsJwtAuth])
async def get_policy_config() -> ResponseSchemaModel[GetConfigDetail]:
async def get_policy_config() -> ResponseSchemaModel[list[GetConfigDetail]]:
config = await config_service.get_built_in_config('policy')
return response_base.success(data=config)

Expand Down
7 changes: 2 additions & 5 deletions backend/app/admin/crud/crud_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def get_by_key_and_type(self, db: AsyncSession, key: str, type: str) -> Co
"""
return await self.select_model_by_column(db, key=key, type=type)

async def get_by_key(self, db: AsyncSession, key: str, built_in: bool = False) -> Config | None:
async def get_by_key(self, db: AsyncSession, key: str) -> Config | None:
"""
通过 key 获取系统配置参数

Expand All @@ -52,10 +52,7 @@ async def get_by_key(self, db: AsyncSession, key: str, built_in: bool = False) -
:param built_in:
:return:
"""
filters = {'key': key}
if not built_in:
filters.update({'type__not_in': admin_settings.CONFIG_BUILT_IN_TYPES})
return await self.select_model_by_column(db, **filters)
return await self.select_model_by_column(db, key=key)

async def get_list(self, name: str = None, type: str = None) -> Select:
"""
Expand Down
6 changes: 5 additions & 1 deletion backend/app/admin/service/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def save_built_in_config(objs: list[SaveBuiltInConfigParam], type: str) ->
for obj in objs:
config = await config_dao.get_by_key_and_type(db, obj.key, type)
if config is None:
if await config_dao.get_by_key(db, obj.key, built_in=True):
if await config_dao.get_by_key(db, obj.key):
raise errors.ForbiddenError(msg=f'参数配置 {obj.key} 已存在')
await config_dao.create_model(db, obj, flush=True, type=type)
else:
Expand Down Expand Up @@ -62,6 +62,10 @@ async def update(*, pk: int, obj: UpdateConfigParam) -> int:
config = await config_dao.get(db, pk)
if not config:
raise errors.NotFoundError(msg='参数配置不存在')
if config.key != obj.key:
config = await config_dao.get_by_key(db, obj.key)
if config:
raise errors.ForbiddenError(msg=f'参数配置 {obj.key} 已存在')
count = await config_dao.update(db, pk, obj)
return count

Expand Down