"github.com/tsinghua-io/api-server/util" "net/http" ) var CourseMaterials = Resource{ "GET": util.AuthNeededHandler(GetCourseMaterials), } var GetCourseMaterials = learn.HandlerFunc(func(rw http.ResponseWriter, req *http.Request, ada *learn.Adapter) { v, status, err := BatchResourceFunc( mux.Vars(req)["id"], func(id string) (interface{}, int, error) { materials := new(model.Materials) sg := util.NewStatusGroup() sg.Go(func(status *int, err *error) { materials.Announcements, *status, *err = ada.Announcements(id) }) sg.Go(func(status *int, err *error) { materials.Files, *status, *err = ada.Files(id) }) sg.Go(func(status *int, err *error) { materials.Assignments, *status, *err = ada.Assignments(id) }) status, err := sg.Wait() return materials, status, err }) util.JSON(rw, v, status, err) })
package resource import ( "github.com/gorilla/mux" "github.com/tsinghua-io/api-server/adapter/tsinghua.edu.cn/x/learn" "github.com/tsinghua-io/api-server/util" "net/http" ) var CourseAssignments = Resource{ "GET": util.AuthNeededHandler(GetCourseAssignments), } var GetCourseAssignments = learn.HandlerFunc(func(rw http.ResponseWriter, req *http.Request, ada *learn.Adapter) { v, status, err := BatchResourceFunc( mux.Vars(req)["id"], func(id string) (interface{}, int, error) { return ada.Assignments(id) }) util.JSON(rw, v, status, err) })
package resource import ( "github.com/tsinghua-io/api-server/adapter/tsinghua.edu.cn/x/learn" "github.com/tsinghua-io/api-server/util" "net/http" ) var Semester = Resource{ "GET": util.AuthNeededHandler(GetSemester), } var GetSemester = learn.HandlerFunc(func(rw http.ResponseWriter, req *http.Request, ada *learn.Adapter) { semester, _, status, err := ada.Semesters() util.JSON(rw, semester, status, err) })
package resource import ( "github.com/tsinghua-io/api-server/adapter/tsinghua.edu.cn/x/learn" "github.com/tsinghua-io/api-server/util" "net/http" ) var Profile = Resource{ "GET": util.AuthNeededHandler(GetProfile), } var GetProfile = learn.HandlerFunc(func(rw http.ResponseWriter, req *http.Request, ada *learn.Adapter) { profile, status, err := ada.Profile() util.JSON(rw, profile, status, err) })
} var GetAttended = learn.HandlerFunc(func(rw http.ResponseWriter, req *http.Request, ada *learn.Adapter) { sem := req.URL.Query().Get("semester") english := (util.Language(req) == language.English) switch sem { case "", "latest": if this, next, status, err := ada.NowAttended(english); len(next) == 0 { util.JSON(rw, this, status, err) } else { util.JSON(rw, next, status, err) } case "this": this, _, status, err := ada.NowAttended(english) util.JSON(rw, this, status, err) case "next": _, next, status, err := ada.NowAttended(english) util.JSON(rw, next, status, err) case "past": past, status, err := ada.PastAttended(english) util.JSON(rw, past, status, err) case "all": all, status, err := ada.AllAttended(english) util.JSON(rw, all, status, err) default: courses, status, err := ada.Attended(sem, english) util.JSON(rw, courses, status, err) } })