You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pk8f3pmu2/data/eduapi.js

214 lines
5.5 KiB

const api_base_url = "https://www.educoder.net/api";
/**
* https://www.educoder.net的api接口通过其实现用户与后端进行交互
*/
export class Account{
static login({session, login, password, autologin, success, fail, complete}) {
console.log("login");
let data = {login: login, password: password, autologin: autologin};
session.request({
url: api_base_url + "/accounts/login.json",
method: "POST",
data: data,
header: {"content-type": "application/json"},
success: (res)=>{
if("status" in res.data && res.data.status<0){
fail(new Error(res.data.message));
return;
}
console.log("type of success:"+ typeof success);
if(typeof success == "function") {
success(res);
}
},
fail: fail,
complete: complete
});
}
static get_user_info({session, success, fail, complete}){
let data = {school: 1}
session.request({
url: api_base_url + "/users/get_user_info.json",
method: "GET",
data: data,
success: success,
fail: fail,
complete: complete
})
}
static get_verification_code({session, login, type, success, fail, complete}){
let data = {login: login, type: type};
//@notice type: 验证码用途 type=1=> 注册 type=2 => 重置密码
session.request({
url: api_base_url + "/accounts/get_verification_code.json",
method: "GET",
data: data,
success: success,
fail: fail,
complete: complete
})
}
static register({session, login, password, code, success, fail, complete}){
let data = {login: login, password: password, code: code};
session.request({
url: api_base_url + "/accounts/register.json",
method: "POST",
data:data,
success(res) {
if("status" in res.data && res.data.status<0){
fail(new Error(res.data.message));
return;
}
success(res);
},
fail: fail,
complete: complete
})
}
static attendance({session, success, fail, complete}){
session.request({
url: api_base_url + "/users/attendance.json",
success(res) {
if("status" in res.data && res.data.status<0){
fail(new Error(res.data.status));
return;
}
if(typeof success == "function"){
success(res);
}
},
fail: fail,
complete: complete
})
}
static logout({session, success, fail, complete}){
session.request({
url: api_base_url + "/accounts/logout.json",
method: "GET",
success: success,
fail: fail,
complete: complete
})
}
}
export class Course{
static create({session, data, success, fail, complete}){
}
static search({session, limit=20, page=1, order="all", search="", success, fail, complete}){
let data = {limit: limit, page: page, order: order, search: search};
return session.request({
url: api_base_url + "/courses.json",
method: "GET",
data: data,
success: success,
fail: fail,
complete: complete
})
}
static join({session, invite_code, professor=null,assistant_professor=null,student=null, success, fail, complete}){
let data = {
invite_code: invite_code,
professor: professor,
assistant_professor: assistant_professor,
student: student
};
return session.request({
url: api_base_url + "/courses/apply_to_join_course.json",
method:"POST",
data: data,
success: res=>{
if("status" in res.data && res.data.status<0){
fail(new Error(res.data.message));
return;
}
if(typeof success == "function"){
success(res);
}
},
fail: fail,
complete: complete
})
}
static get_user_info({session, course_id, success, fail, complete}){
let data = {course_id: course_id, school: 1}
return session.request({
url: api_base_url + "/users/get_user_info.json",
method: "GET",
data: data,
success: success,
fail: fail,
complete: complete
})
}
static get_students({session, course_id, order=1,sort="asc",page=1, limit=20, course_group_id="", success, fail, complete}){
let data = {
order: order,
sort: sort,
page: page,
limit: limit,
course_group_id: course_group_id
};
return session.request({
url: api_base_url + "/courses/" + course_id + "/students.json",
method: "GET",
data: data,
success(res){
if("status" in res.data && "message" in res.data){
fail(new Error(res.data.message));
return;
}
success(res);
},
fail: fail,
complete: complete
})
}
}
export class Exercise{
static search({session,course_id,page=1, limit=15, success, fail, complete}){
let data = {page:page, limit:limit};
return session.request({
url: api_base_url + "/courses/"+course_id+"/exercises,json",
method: "GET",
data: data,
success: success,
fail:fail,
complete: complete
})
}
static start_answer({session, exercise_id, login, success, fail, complete}){
let data = {login: login};
return session.request({
url: api_base_url + "/exercises/" + exercise_id + "/start_answer.json",
method: "GET",
data: data,
success: success,
fail: fail,
complete: complete
})
}
}
export class ExerciseQuestion {
static answer({session, question_id, exercise_choice_id, login, success, fail, complete}){
let data = {exercise_choice_id: exercise_choice_id};
return session.request({
url: api_base_url + "/exercise_questions/" + question_id +"/exercise_answer.json",
method: "POST",
data: data,
success: success,
fail: fail,
complete: complete
})
}
}
export class Ui{
}