diff --git a/apps/openapi/views.py b/apps/openapi/views.py index c591b81b26..58e7be2e91 100644 --- a/apps/openapi/views.py +++ b/apps/openapi/views.py @@ -6,7 +6,7 @@ from apps.openapi.serializer import ProxyNodeSerializer, UserInfoSerializer from apps.openapi.utils import OpenAPIStaffAuthentication, gen_common_error_response from apps.proxy.models import ProxyNode -from apps.sspanel.models import UserCheckInLog +from apps.sspanel.models import UserCheckInLog, UserSocialProfile class BaseOpenAPIViewSet(ModelViewSet): @@ -80,3 +80,19 @@ def checkin(self, request, pk): "increased_traffic": log.increased_traffic, } return JsonResponse(data=data) + + @action(detail=False, methods=["post"]) + def search(self, request): + platform = request.data.get("platform") + platform_user_id = request.data.get("platform_user_id") + if not platform or not platform_user_id: + return gen_common_error_response( + "platform and platform_user_id in body is required" + ) + user = UserSocialProfile.get_by_platform_user_id(platform, platform_user_id) + if not user: + return gen_common_error_response( + f"user with platform:{platform} platform_user_id:{platform_user_id} not found", + status=404, + ) + return JsonResponse(self.serializer_class(user).data) diff --git a/spec/openapi.yaml b/spec/openapi.yaml index 97d07f82ed..2d5c71c302 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -97,6 +97,20 @@ components: type: boolean description: Whether to enable or disable the ProxyNode # TODO Add more properties as needed + + SearchUserReq: + type: object + properties: + platform: + type: string + description: platform + platform_user_id: + type: string + description: platform user id + required: + - platform + - platform_user_id + UserInfo: type: object properties: @@ -307,6 +321,31 @@ paths: schema: $ref: "#/components/schemas/CommonErrorResp" + /users/search/: + post: + summary: search user + tags: + - User + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/SearchUserReq" + responses: + 200: + description: Successful + content: + application/json: + schema: + $ref: "#/components/schemas/UserInfo" + 400: + description: Bad request + content: + application/json: + schema: + $ref: "#/components/schemas/CommonErrorResp" + /users/{id}/info/: get: summary: Get UserInfo