예제 #1
0
// this function only generate a task and add it into `tasks`
func addTask(taskdata icarus.TaskData) (t *task.Task, err error) {
	c, err := client.GetHandle(taskdata.Handle)
	if err != nil {
		return
	}
	var user icarus.User
	user, err = client.MakeUserByData(c, taskdata.User)
	if err != nil {
		return
	}
	courses := make([]icarus.Course, 0)
	for _, csData := range taskdata.Courses {
		var cs icarus.Course
		cs, err = client.MakeCourceByData(c, csData)
		if err != nil {
			return
		}
		courses = append(courses, cs)
	}

	t = task.NewTask(user, courses)
	tasks[taskdata.ID] = TaskEntry{
		Header:   taskdata,
		Instance: t,
	}

	return
}
예제 #2
0
// After `ParseHandle`
func ParseUser(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
	var ud icarus.UserData
	err := GetJSONKeyAs(ctx, "user", &ud)
	if err != nil {
		WriteJSON(w, http.StatusBadRequest, BadField("user"))
		return nil
	}
	cli := GetHandle(ctx)
	u, err := client.MakeUserByData(cli, ud)
	if err != nil {
		WriteJSON(w, http.StatusBadRequest, BadMake("user"))
		return nil
	}
	newCtx := context.WithValue(ctx, keyUser, u)
	return context.WithValue(newCtx, keyUserData, ud)
}