Skip to content

Commit

Permalink
feat: Add search user openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Jan 17, 2024
1 parent 1a48a8b commit 1aac3fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apps/openapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
39 changes: 39 additions & 0 deletions spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1aac3fc

Please sign in to comment.