Ejemplo n.º 1
0
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)
})
Ejemplo n.º 2
0
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/model"
	"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)
			})
Ejemplo n.º 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)
})
Ejemplo n.º 4
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)
})
Ejemplo n.º 5
0
package resource

import (
	"github.com/tsinghua-io/api-server/adapter/tsinghua.edu.cn/x/learn"
	"github.com/tsinghua-io/api-server/util"
	"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":
Ejemplo n.º 6
0
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 CourseAnnouncements = Resource{
	"GET": util.AuthNeededHandler(GetCourseAnnouncements),
}

var GetCourseAnnouncements = 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.Announcements(id)
		})
	util.JSON(rw, v, status, err)
})
Ejemplo n.º 7
0
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 CourseFiles = Resource{
	"GET": util.AuthNeededHandler(GetCourseFiles),
}

var GetCourseFiles = 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.Files(id)
		})
	util.JSON(rw, v, status, err)
})