by TYJ, ZHD
2020/04/05
Cat = {
"name": string,
"catID": number,
"avatar": url (string)
}
Archive = {
"name": string,
"photos": [
url (string),
],
"introduction": string,
"relatedCats": [{
"relatedCat": Cat,
"relation": string
}]
}
User = {
"name": string,
"userID": number,
}
UserProfile = {
"user": User,
"avatar": url (string),
"email": string,
"whatsup": string
}
Feeder_application = {
"applicationID": number,
"user": User,
"apply_info": string,
"cat": Cat
}
Post = {
// 这里的postID在创建post时无效
"postID": number,
"publisher": PublisherInfo,
"time": "2020-04-05 16:02" (string),
"text": string,
"multimediaContent": [
url (string),
],
"commentList": CommentList,
"favor": {
"self": number, // 1表示自己点赞了
"favorCnt": number,
}
}
PublisherInfo = {
"userID": number,
"username": string,
"avatar": url (string)
}
CommentList = {
"rootType": string, // cat or post
"rootID", number,
"totalCount": number,
"downloadCount": number,
"start": number,
"comments": [
Comment,
]
}
// 暂时没有考虑评论嵌套
Comment = {
"commentID": number,
"user": User,
"text": string
}
body中code相关约定
见src/backend/config.py
CODE = {
"success": 200,
"database_error": 300,
"user_error": 400,
"method_error": 600,
"parameter_error": 700,
}
服务器响应body的基本数据格式
其中data为json
// 通用:
{
"code": xxx,
"data": {
"msg": string,
xxx: xxx
}
}
// 成功:
{
"code": 200,
"data": {
"msg": "success"
}
}
// 用户无权限
response.body = {
"code": 400,
"data": {
"msg": "not authorized"
}
}
// 用户未登录
response.body = {
"code": 400,
"data": {
"msg": "user not logged in"
}
}
// 方法错误:
{
"code": 600,
"data": {
"msg": "wrong method"
}
}
// 参数错误:
{
"code": 700,
"data": {
"msg": "wrong parameter"
}
}
每个接口的具体设计
/user
/user/login
/user/register
/user/register/validation
/user/logout
/user/profile
/feeder
/feeders
/feeder/apply
/feeder/applys
/post
/posts
/post/favor
/post/comment
/post/comments
/archive
/archives
/file
POST /file
request.body = {
"picture": [file1, file2, ...],
"video": [file3, file4, ...]
}
// 上传成功:
response.body = {
"code": 200,
"data": {
"msg": "success",
"picture": [url1, url2, ...],
"video": [url1, url2, ...],
}
}
// 上传失败:
response.body = {
"code": 700,
"data": {
"msg": "parameter error",
}
}
POST /user/login
request.body = {
"email": "1600012607" (string, pku邮箱名,不包括@pku.edu.cn)
"password": string
}
// 登录成功
response.body = {
"code": 200,
"data": {
"msg": "success",
"profile": Userprofile
}
}
// 在登录状态下登录其他账号
response.body = {
"code": 400,
"data": {
"msg": "error"
}
}
// 参数错误(缺少邮箱密码、用户不存在):
response.body = {
"code": 300,
"data": {
"msg": "wrong parameter"
}
}
// 登陆失败:
response.body = {
"code": 300,
"data": {
"msg": "email or password error"
}
}
POST /user/register
request.body = {
"email": "1600012607" (string, pku邮箱名,不包括@pku.edu.cn)
}
// 成功
response.body = {
"code": 200,
"data": {
"msg": "success"
}
}
// 邮箱已注册:
response.body = {
"code": 300,
"data": {
"msg": "email address already registered"
}
}
// 30s内重复请求:
response.body = {
"code": 400,
"data": {
"msg": "repeated acquisition in 30 seconds"
}
}
// 邮箱格式错误:
response.body = {
"code": 700,
"data": {
"msg": "wrong email"
}
}
POST /user/register/validation
request.body = {
"username": "pkucat" (string),
"password": "pkucat2020" (string),
"email": "1600012607" (string, pku邮箱名,不包括@pku.edu.cn),
"verificationCode": "666666" (string),
}
// 验证成功(并登录)
response.body = {
"code": 200,
"data": {
"msg": "success",
"profile": Userprofile
}
}
// 用户名重复:
response.body = {
"code": 300,
"data": {
"msg": "duplicate username"
}
}
// 验证码错误:
response.body = {
"code": 700,
"data": {
"msg": "wrong verification code"
}
}
// 邮箱错误:
response.body = {
"code": 700,
"data": {
"msg": "wrong email"
}
}
// 邮箱已注册:
response.body = {
"code": 300,
"data": {
"msg": "email address already registered"
}
}
POST /user/logout
request.body = { }
// 成功
response.body = {
"code": 200,
"data": {
"msg": "success"
}
}
GET /user/profile
request.body = {
"userID": number, // 可选参数,id为空则查看自己的个人信息
}
// 成功返回
response.body = {
"code": 200,
"data": {
"msg": "success",
"profile": Userprofile
}
}
// 用户不存在
response.body = {
"code": 300,
"data": {
"msg": "user does not exist",
"profile": {}
}
}
PUT /user/profile
request.body = { // 三项至少一个不为空
"avatar": string,
"whatsup": string,
"username": string
}
// 成功
response.body = {
"code": 200,
"data": {
"msg": "success"
}
}
// 用户名重复
response.body = {
"code": 300,
"data": {
"msg": "duplicate username"
}
}
// 三项均为空
response.body = {
"code": 300,
"data": {
"msg": "parameter error"
}
}
// 用户名重复
response.body = {
"code": 300,
"data": {
"msg": "duplicate username"
}
}
// 头像文件不存在
response.body = {
"code": 300,
"data": {
"msg": "unexisted avatar"
}
}
// 用户名重复且头像文件不存在
response.body = {
"code": 300,
"data": {
"msg": "duplicate username/unexisted avatar"
}
}
POST /feeder/apply
request.body = {
"catID": number,
"apply_info": string
}
// 已成为饲养员
response.body = {
"code": 300,
"data": {
"msg": "already been feeder"
}
}
GET /feeders
// 成功返回
response.body = {
"code": 200,
"data": {
"msg": "success",
"feeders": [
User,
]
}
}
GET /feeder/applys
// 成功
response.body = {
"code": 200,
"data": {
"msg": "success",
"applies": [
{
"applyID": number,
"userID": number,
"catID": number
}
]
}
}
POST /feeder/agree
request.body = {
"applyID": number,
}
// 失败
response.body = {
"code": 300,
"data": {
"msg": "wrong parameter",
}
}
DELETE /feeder/apply
request.body = {
"applyID": number,
}
// 失败
response.body = {
"code": 300,
"data": {
"msg": "wrong parameter",
}
}
POST /post
request.body = {
"post": Post,
}
// 失败
response.body = {
"code": 700,
"data": {
"msg": "wrong parameter",
}
}
DELETE /post?id=123
// 成功
response.body = {
"code": 200,
"data": {
"msg": "delete post successfully"
}
}
GET /posts?limit=10&start=10&comments=10
limit默认为10,start默认为1,表示从第一条动态开始,comments默认为10,表示下载10条最新评论
response = {
"code": 200,
"data": {
"downloadCount": number,
"data": [
Post,
]
}
}
GET /posts/search?catid=123&userid=123&keyword=大威&comments=10
cat-id表示猫咪的id,user-id表示用户id,keyword表示关键词,这三个参数至少有一个不为空,都为空返回结果同请求动态列表(时间顺序)
comments默认为10,表示顺便下载10条最新评论
response = {
"code": 200,
"data": {
"downloadCount": number,
"data": [
Post,
]
}
}
GET /post/comments?type=post&root-id=123&limit=10&start=10
response = {
"code": 200,
"data": {
"commentList": CommentList
}
}
PUT /post/favor
request.body = {
"postID": number
}
DELETE /post/favor
request.body = {
"postID": number
}
POST /post/comment
request.body = {
"postID": number,
"text": string,
}
// 动态不存在
response = {
"code": 300,
"data": {
"msg": "post not exists",
}
}
GET /archives
// 成功返回
resonse.body = {
"code": 200,
"data": {
"msg": "success",
"catList": [
Cat,
]
}
}
GET /archive?catid=10
// 成功返回
resonse.body = {
"code": 200,
"data": {
"msg": "success",
"archive": Archive
}
}
PUT /archive
request.body = {
"catID": number,
"introcudtion": string,
"addPhotos": [
image,
],
"deleteImages": [
url (string),
],
"relatedCats": [{
"relatedCat": Cat,
"relation": string
}]
}
POST /archive
request.body = {
"catName": string,
"introduction": string,
"photos": [
image,
],
"relatedCats": [{
"relatedCat": Cat,
"relation": string
}]
}
// 成功添加
response.body = {
"code": 200,
"data": {
"msg": "success",
"catID": number
}
}
GET /archive?keyword="大威"
// 搜索结果
response.body = {
"code": 200,
"data": {
"msg": "success",
"results": [
Cat,
]
}
}