Skip to content

Commit 4917078

Browse files
committed
Update some interface definitions
1 parent 98e09ce commit 4917078

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

backend/plugin/oauth2/api/v1/user_social.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
from backend.common.security.jwt import DependsJwtAuth
55
from backend.database.db import CurrentSession, CurrentSessionTransaction
66
from backend.plugin.oauth2.enums import UserSocialType
7-
from backend.plugin.oauth2.schema.user_social import GetUserSocialDetail
87
from backend.plugin.oauth2.service.user_social_service import user_social_service
98

109
router = APIRouter()
1110

1211

1312
@router.get('/me/bindings', summary='获取用户已绑定的社交账号', dependencies=[DependsJwtAuth])
14-
async def get_user_bindings(db: CurrentSession, request: Request) -> ResponseSchemaModel[GetUserSocialDetail]:
13+
async def get_user_bindings(db: CurrentSession, request: Request) -> ResponseSchemaModel[list[str]]:
1514
bindings = await user_social_service.get_bindings(db=db, user_id=request.user.id)
1615
return response_base.success(data=bindings)
1716

1817

19-
@router.get('/me/binding/{source}', summary='获取绑定授权链接', dependencies=[DependsJwtAuth])
18+
@router.get('/me/binding', summary='获取绑定授权链接', dependencies=[DependsJwtAuth])
2019
async def get_binding_auth_url(request: Request, source: UserSocialType) -> ResponseSchemaModel[str]:
21-
binding_url = user_social_service.get_binding_auth_url(user_id=request.user.id, source=source)
20+
binding_url = await user_social_service.get_binding_auth_url(user_id=request.user.id, source=source)
2221
return response_base.success(data=binding_url)
2322

2423

backend/plugin/oauth2/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
class UserSocialType(StrEnum):
55
"""用户社交类型"""
66

7-
github = 'GitHub'
7+
github = 'Github'
88
google = 'Google'
99
linux_do = 'LinuxDo'

backend/plugin/oauth2/service/user_social_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import json
22
import uuid
33

4-
from collections.abc import Sequence
5-
64
from sqlalchemy.ext.asyncio import AsyncSession
75

86
from backend.common.exception import errors
97
from backend.core.conf import settings
108
from backend.database.redis import redis_client
119
from backend.plugin.oauth2.crud.crud_user_social import user_social_dao
1210
from backend.plugin.oauth2.enums import UserSocialType
13-
from backend.plugin.oauth2.model import UserSocial
1411
from backend.plugin.oauth2.schema.user_social import CreateUserSocialParam
1512

1613

1714
class UserSocialService:
1815
@staticmethod
19-
async def get_bindings(*, db: AsyncSession, user_id: int) -> Sequence[UserSocial]:
16+
async def get_bindings(*, db: AsyncSession, user_id: int) -> list[str]:
2017
"""
2118
获取用户已绑定的社交账号
2219
2320
:param db: 数据库会话
2421
:param user_id: 用户 ID
2522
:return: 绑定列表,每个元素包含 sid、source 等信息
2623
"""
27-
return await user_social_dao.get_by_user_id(db, user_id)
24+
bindings = await user_social_dao.get_by_user_id(db, user_id)
25+
return [binding.source for binding in bindings]
2826

2927
@staticmethod
3028
async def binding_with_oauth2(

0 commit comments

Comments
 (0)