后端接口文档 - noenergysoftware/rateMyCourse GitHub Wiki

后端接口文档

本文档主要介绍了项目目前的接口功能,URL,需求,返回值等信息,以帮助前端更好对接及开发者进行测试。


sign_in

用户登录接口

访问URL

r'^signIn/$'

模式

POST

传入需求

username:用户名
mail :邮箱
password:密码

其中username和mail需求一个即可,优先匹配username。

操作成功传出内容

{
    'status': 1,
    'length': 1,
    'body': {
        'username': u.username
    }
}

sign_up

用户注册接口

访问URL

r'^signUp/$'

模式

POST

传入需求

username:用户名 unique
mail :邮箱 unique
password:密码
Ticket: 腾讯验证码的Ticket
Randstr: 腾讯验证码生成的Randstr
UserIP:用户IP地址

操作成功传出内容

{
    'status':1,
    'length':1,
    'body':{
        'message': "新建用户{0}成功".format(username)},errMsg='',
    }
}

update_user

更新用户个人信息

访问URL

r'^updateUser/$'

模式

POST,需要检查cookie和session的合法性

传入需求

用户更新,至少包含username,其他内容为可选项(用来更新旧内容)

username:用户名
role:角色,使用'T', 'S', 'O'这类简写,e.g.[ ROLE_CHOICE = (
        ('T', 'Teacher'),
        ('S', 'Student'),
        ('O', 'Other'),
    )]
gender:性别,使用简写,e.g.[ GENDER_CHOICE = (
        ('M', 'Male'),
        ('F', 'Female'),
        ('A', 'Anonymous'),
    )]
self_introduction:自我介绍,字数上限256

操作成功传出内容

{
    'status':1,
    'length':1,
    'body':{'message': "用户{0}信息更新成功".format(username)},
    errMsg='',
}

logout

用户登出接口

访问URL

r'^logout/$'

模式

POST,需要检测cookie和session的合法性

传入需求

登出,至少包含以下键

username

操作成功传出内容

{
    'status': 1,
    'length': 1,
    'body': {
        'message': '登出成功'
    }
}

get_token

获取CSRF令牌

访问URL

r'^getToken/$'

模式

get

传入需求

操作成功传出内容

{'token': token}

delete_user

删除用户

访问URL

r'^deleteUser/$'

模式

POST,需要检验cookie和session的合法性

传入需求

username=用户名
password=用户密码

操作成功传出内容

{
    'status': 1,
    'body': '删除成功',
}

search_teacher

搜索教师接口

访问URL

r'^searchTeacher/***$'

模式

get

传入需求

搜索教师,至少包含以下键

teacher_name:教师名字(contain)

操作成功传出内容

{
    'status': 1,
    'length': len(teacher_list),
    'body': [{'name': self.name,
            'website': self.website,
            'title': self.title},...],
    errMsg=''
}

search_course

搜索课程接口

访问URL

r'^searchCourse/***$'

模式

get

传入需求

搜索课程,至少包含以下键

course_name:课程名字(contain)

操作成功传出内容

{
    'status': 1, 
    'length': len(course_list),
    'body': [{'name': self.name,
            'website': self.website,
            'course_ID': self.course_ID,
            'description': self.description,
            'course_type': self.course_type,
            'credit': self.credit},teacher_list...,'department'=],
    errMsg=""
}

search_user

搜索用户接口

访问URL

r'^searchUser/***$'

模式

get

传入需求

搜索用户,至少包含以下键

username:用户名字(contain)

操作成功传出内容

{
    'status': 1, 
    'length': len(user_list),
    'body': [{'username': self.username,
            'mail': self.mail,
            'role': self.role,
            'gender': self.gender,
            'self_introduction': self.self_introduction},...],
    errMsg=""
}

get_user_detail

获取用户信息

访问URL

r'^getUserDetail/***$'

模式

get

传入需求

搜索用户,至少包含以下键

username:用户名字(唯一匹配)

操作成功传出内容

{
    'status': 1, 
    'length': 1,
    'body': {'username': self.username,
            'mail': self.mail,
            'role': self.role,
            'gender': self.gender,
            'self_introduction': self.self_introduction},
    errMsg=""
}

get_user_profile_photo

获取用户头像

访问URL

r'^getUserProfilePhoto/***$'

模式

get

传入需求

username:用户名字(唯一匹配)

操作成功传出内容

{
    'status': 1, 
    'length': 1,
    'body': {profile_photo: user.profile_photo},
    errMsg=""
}

search_course_by_department

按部门搜索课程

访问URL

r'^searchCourseByDepartment/$'

模式

GET

传入需求

department: 完整正确的学院名
course_name: 完整正确的课程名

操作成功传出内容

类似searchCourse,只是将搜索范围限定到某个学院。


get_department

获取学院列表

访问URL

r'^getDepartment/$'

模式

GET

操作成功传出内容

成功:body返回一个list,包括所有学院的信息


update_user_profile_photo

获取学院列表

访问URL

r'^updateUserProfilePhoto/$'

模式

POST,需要检查cookie和session的合法性

传入需求

至少包含以下键

username :用户名
profile_photo :更新的头像链接

操作成功传出内容

{ 'status': 1, 'length': 1, 'body': { 'message': "成功更新用户{0}的头像".format(user.username) } }


add_select_course

增加关注课程

访问URL

r'^addselectCourse/$'

模式

POST,需要检验cookie和session的合法性

传入需求

至少包含以下键

user_id:学生id,
course_list:课程列表,
department_list:课程所属部门列表

操作成功传出内容

成功:{'status':1,'length':1,'body':{'message': "添加课程关注成功".format(username)},errMsg='',}
失败:{'status'=-1}

del_select_course

删除关注课程

访问URL

r'^delselectCourse/$'

模式

POST,需要检验cookie和session的合法性

传入需求

至少包含以下键

user_id:学生id,
course_list:课程列表,
department_list:课程所属部门列表

操作成功传出内容

成功:{'status':1,'length':1,'body':{'message': "移除关注成功".format(username)},errMsg='',}
失败:{'status'=-1}

make_comment

发表评论

访问URL

r'^makeComment/$'

模式

post,需要检验cookie和session的合法性

传入需求

课程评论,至少包含以下键

username:用户名,
course_ID:课程id,
teacher_name: 教师名
content:评论内容,字数上限2048
parent_comment:父评论id

其中父评论id为-1表示没有父评论,且不是必选项(缺失默认为-1)

操作成功传出内容

{
    'status':1,
    'length':1,
    'body':{'message': "评论发布成功"},
    errMsg='',
}

get_comment_by_course

获取课程评论

访问URL

r'^getCommentsByCourse/$'

模式

GET

传入需求

根据课程id获得相应评论,至少包含以下键

course_ID:课程id

操作成功传出内容

在body中返回一个list,每项包含

rdict['username']=i.user.username
rdict['content']=i.comment.content
rdict['editTime']=i.comment.edit_time
rdict['createTime']=i.comment.create_time
rdict['commentID']=i.id

get_comment_by_teacher

获取课程下某教师的评论

访问URL

r'^getCommentsByTeacher/$'

模式

GET

传入需求

根据课程id获得相应评论,至少包含以下键

course_ID:课程id
teacher_ID:教师id

操作成功传出内容

在body中返回一个list,每项包含

rdict['username']=i.user.username
rdict['content']=i.comment.content
rdict['editTime']=i.comment.edit_time
rdict['createTime']=i.comment.create_time
rdict['commentID']=i.id

edit_comment

编辑评论

访问URL

r'^editComment/$'

模式

POST,需要检验cookie和session的合法性

传入需求

至少包括以下键

comment_id:评论id
content:评论内容,字数上限2048,teacher_name: 教师名

操作成功传出内容

成功:

{
    'status':1,
    'length':1,
    'body':{'message': "评论更新成功"},
    errMsg=''
}

rate_comment

点赞/点踩评论

访问URL

r'^rateComment/$'

模式

POST,需要检验cookie和session的正确性

传入需求

课程评分,至少包含以下键

username = 用户名
comment_ID = 评论id
type = agree/disagree

操作成功传出内容

成功:

{
    'status':1,
    'length':1,
    'body':{'message': ...},
    errMsg=''
}

get_rate_comment

获取评论的赞数

访问URL

r'^getRateComment/$'

模式

get

传入需求

课程评分,至少包含以下键

comment_ID = 评论id

操作成功传出内容

成功:

{
    'status': 1,
    'length': 1,
    'body': {'rate': comment.rate}
}

get_high_rate_comment

获取高赞评论

访问URL

r'^getHotComment/$'

模式

get

传入需求

课程评分,至少包含以下键

course_ID = 课程ID

操作成功传出内容

成功:

{
    'status': 1,
    'length': len(retList),
    'body': 高赞评论,
}

make_rank

对课程打分

访问URL

r'^makeRank/$'

模式

POST,需要检验cookie和session的正确性

传入需求

课程评分,至少包含以下键

username:用户名,
course_ID:课程id,
difficulty_score:有趣程度,整形,1-5
funny_score:有趣程度,整形,1-5
gain_score:收获指数,整形,1-5
recommend_score:推荐指数,整形,1-5

操作成功传出内容

成功:

{
    'status':1,
    'length':1,
    'body':{'message': "评分发布成功"},
    errMsg=''
}

附加说明

新评价会覆盖已有评价


get_rank_by_course

获取一门课的评分

访问URL

r'^getRankByCourse/$'

模式

GET

传入需求

根据课程id获得相应评论,至少包含以下键

course_ID:课程id

操作成功传出内容

成功:

{
    'status': 1,
    'length': 评分人数,
    'body': {
        'difficulty_score', 
        'funny_score', 
        'gain_score', 
        'recommend_score'
    }
}

get_rank_by_sorted_course

获取排名较高的课程

访问URL

r'^getRankBySortedCourse/$'

模式

GET

传入需求

操作成功传出内容

成功:

{
    'status': 1,
    'length': len(body),
    'body': [{'course_info','position','people',
        'difficulty_score', 
        'funny_score', 
        'gain_score', 
        'recommend_score'
    },...]
}

get_rank_by_sorted_teacher

获取排名较高的教师

访问URL

r'^getRankBySortedTeacher/$'

模式

GET

传入需求

操作成功传出内容

成功:

{
    'status': 1,
    'length': len(body),
    'body': [{'teacher_info','position','people',
        'difficulty_score', 
        'funny_score', 
        'gain_score', 
        'recommend_score'
    },...]
}

get_all_rank

获取所有课程的评分

访问URL

r'^getAllRank/$'

模式

GET

传入需求

操作成功传出内容

成功:

{
    'status': 1,
    'length': len(body),
    'body': [{'teacher_info','position','people',
        'difficulty_score', 
        'funny_score', 
        'gain_score', 
        'recommend_score'
    },...]
}

set_question

设置密保问题

访问URL

r'^setQuestion/$'

模式

POST,需要检验cookie和session的正确性

传入需求

至少包含以下键

username = 用户名
question = 问题
answer = 答案

操作成功传出内容

成功:

{
    'status':1,
    'length':1,
    'body':{'message': "问题设置成功"},
    'errMsg':'',
}

reset_password

重置密码

访问URL

r'^resetPassword/$'

模式

POST

传入需求

至少包含以下键

username = 用户名
question = 问题
answer = 答案
npassword = 新密码

操作成功传出内容

成功:

{
    'status':1,
    'length':1,
    'body':{'message': "密码重置成功"},
    'errMsg':'',
}