@ranger-01
2019-06-15T23:24:01.000000Z
字数 4057
阅读 649
django
angular
deploy
mimi_program
Filed | Type | introduction |
---|---|---|
user | User | oneToOne filed to user |
unionId | charField | id from weixin |
nickName | charField | wechat nickname from weixin |
avatarUrl | charField | wechat img from weixin |
type | inteter | choice from: visitor, employee, admin |
2. Book
Filed | Type | introduction |
---|---|---|
created | datetime | the time when this item added in database |
doubanId | integer | the book id from douban |
status | integer | choice form: market, wishlist, library, borrowed |
owner | user | ForeignKey to pyuser; who has the owership of the book |
wisher | user | ManyToManyField to pyuser; who wish to buy this book |
login
# login from backend ui
URL: /api/v1/ologin/
method: POST
Data:
{
'username': 'name',
'password': 'password'
}
ret:
{
access_token: "Ro6yB0jLu7xubC6zTbAox4cEb9eXgy"
expires_in: 36000
refresh_token: "7O7jpcl0HgC8quMD8WbfwdPm7DO3Qd"
scope: "read write"
token_type: "Bearer"
}
# login from mini program
URL: /api/v1/wxlogin/
method: POST
Data:
{
'code': 'xxxxxxx',
'userinfo': {
{
"nickName": "NICKNAME",
"gender": GENDER,
"city": "CITY",
"province": "PROVINCE",
"country": "COUNTRY",
"avatarUrl": "AVATARURL",
}
}
ret:
{
"token": token.token,
"token_type": "Bearer",
"user_type": pu.type,
"user_id": u.id
}
user operation
# operation on a user
URL: /api/v1/pyuser/
method: POST
Data:
{
'uid': 'user id',
'operation': 'join, leave'
}
ret:
{
'id': u.id,
'nickname': u.pyuser.nickname,
'avatarUrl': u.pyuser.avatarUrl,
'type': u.pyuser.type,
'date_joined': u.date_joined,
'borrowed_num': Book.objects.filter(owner=u, status=BOOK_STATUS_BORROWED).count()
}
# get pyuser list info
URL: /api/v1/pyusers/
method: GET
Data:
{}
ret:
{
data: [
{
'id': py_user.user.id,
'nickname': py_user.nickname,
'avatarUrl': py_user.avatarUrl,
'type': py_user.type,
'date_joined': py_user.user.date_joined,
'borrowed_num': Book.objects.filter(owner=py_user.user, status=BOOK_STATUS_BORROWED).count()
},
]
}
book operation
# operation on a book
URL: /api/v1/book/
method: POST
Data:
{
'operation': 'wish, buy, borrow, return',
'book_id': '123'
}
ret:
{
'book_info': book_info,
'status': book.status,
'owner': book_owner,
'wishers': book.wishers.all().values(
'id', 'pyuser__nickname', 'pyuser__avatarUrl'
)
}
# get book list info
URL: /api/v1/books/
method: GET
Data:
{
'type': 'wish, all',
}
ret:
{
data: [
{
'book_info': str_book_info,
'status': book.status,
'owner': {
'id': book.owner.id,
'nickname': book.owner.pyuser.nickname,
'avatarUrl': book.owner.pyuser.avatarUrl
},
'wishers': book.wishers.all().values(
'id', 'pyuser__nickname', 'pyuser__avatarUrl'
)
},
]
}
Book status
Book operation
borrow the book
return the book