예제 #1
0
	"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)
})
예제 #2
0
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)
})
예제 #3
0
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)
})
예제 #4
0
	"golang.org/x/text/language"
	"net/http"
)

var Attended = Resource{
	"GET": util.AuthNeededHandler(GetAttended),
}

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)