Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
增加根据用户名查询用户信息接口
Browse files Browse the repository at this point in the history
  • Loading branch information
gwind committed Apr 16, 2019
1 parent 4bb7f2e commit 10f22ff
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/codebase/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ def _remove_user(self, user):
self.db.delete(user)

self.db.commit()


class UserByNameHandler(APIRequestHandler):

def get(self, username):
user = self.db.query(User).filter_by(username=username).first()
if not user:
raise HTTPError(400, reason="not-found")
self.success(data=user.ifull)
42 changes: 41 additions & 1 deletion src/codebase/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,46 @@ paths:
$ref: '#/definitions/DefaultErrorResponse'


"/user/by_name/{username}":

parameters:
- $ref: '#/parameters/Authorization'
- name: username
in: path
type: string
required: true
minLength: 2
maxLength: 32
description: 用户名

get:
tags:
- user
x-roles:
- admin
summary: 给定用户名,查看用户信息
responses:
"200":
description: OK
schema:
type: object
required:
- status
- data
properties:
status:
$ref: '#/definitions/Status'
data:
$ref: '#/definitions/User'
default:
description: |
返回错误信息
error 值及含义:
- `not-found` : 用户不存在
schema:
$ref: '#/definitions/DefaultErrorResponse'


definitions:

Status:
Expand Down Expand Up @@ -749,7 +789,7 @@ definitions:
id:
type: string
format: uuid
description: 应用ID
description: 用户ID
is_active:
type: boolean
description: 是否启用
Expand Down
3 changes: 3 additions & 0 deletions src/codebase/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
r"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})",
user.SingleUserHandler),

url(r"/user/by_name/(.*)",
user.UserByNameHandler),

# App

url(r"/app",
Expand Down
26 changes: 26 additions & 0 deletions tests/api_testing/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,29 @@ def test_delete_success(self):
self.assertEqual(self.db.query(App).count(), 1)
user = self.db.query(User).filter_by(username=username).first()
self.assertIsNone(user)


class UserByNameTestCase(_Base):
"""GET /user/by_name/{username} - 指定用户名,查看用户详情
"""

def test_not_found(self):
"""用户不存在
"""

resp = self.api_get("/user/by_name/not_exist")
self.validate_not_found(resp)

def test_view_success(self):
"""查看成功
"""
resp = self.api_get(f"/user/by_name/{self.current_user.username}")
body = get_body_json(resp)
self.assertEqual(resp.code, 200)
self.validate_default_success(body)

spec = self.rs.get_user_by_name_username.op_spec["responses"]["200"]["schema"]
api.validate_object(spec, body)

data = body["data"]
self.assertEqual(data["username"], self.current_username)

0 comments on commit 10f22ff

Please sign in to comment.