Example #1
0
func MockCoduno(w http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	q := model.NewQueryForCompany().Filter("Name =", "Coduno").Limit(1).KeysOnly()

	var companies []model.Company

	keys, err := q.GetAll(ctx, companies)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	coduno := keys[0]

	model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Hello, world!",
				Description:  "This is the easiest program. It is the hello world of this challenge.",
				Instructions: "Implement a program that outputs \"Hello, world!\" in a programming language of your choice.",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 0, 0},
		},
		Runner:    "simple",
		Languages: []string{"java", "py", "c", "cpp"},
	}.SaveWithParent(ctx, coduno)
}
Example #2
0
// PostCompany creates a new company after validating by key.
func PostCompany(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	if r.Method != "POST" {
		return http.StatusMethodNotAllowed, nil
	}

	var company model.Company
	if err = json.NewDecoder(r.Body).Decode(&company); err != nil {
		return http.StatusBadRequest, err
	}

	var companies model.Companys
	_, err = model.NewQueryForCompany().
		Filter("Address =", company.Address.Address).
		Limit(1).
		GetAll(ctx, &companies)

	if err != nil {
		return http.StatusInternalServerError, err
	}

	if len(companies) > 0 {
		return http.StatusConflict, errors.New("already registered")
	}

	var key *datastore.Key
	if key, err = company.Put(ctx, nil); err != nil {
		return http.StatusInternalServerError, err
	}

	// TODO(flowlo): Respond with HTTP 201 and include a
	// location header and caching information.

	json.NewEncoder(w).Encode(company.Key(key))
	return http.StatusOK, nil
}
Example #3
0
func MockChallenge(w http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	q := model.NewQueryForCompany().Filter("Name =", "Coduno").Limit(1).KeysOnly()

	var companies []model.Company

	keys, err := q.GetAll(ctx, companies)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	coduno := keys[0]

	taskOne, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Hello, world!",
				Description:  "This is the easiest program. It is the hello world of this challenge.",
				Instructions: "Implement a program that outputs \"Hello, world!\" in a programming language of your choice.",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 0, 0},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	taskTwo, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Sorting",
				Description:  "This program will require some knowledge about algorithms.",
				Instructions: "Implement a simple bubble sorter on numbers in a programming language of your choice.",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 2, 3},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	taskThree, _ := model.CodeTask{
		Task: model.Task{
			Assignment: model.Assignment{
				Name:         "Some task",
				Description:  "Description of some task",
				Instructions: "Instructions of some task",
				Duration:     time.Hour,
				Endpoints: model.Endpoints{
					WebInterface: "simple-code-task",
				},
			},
			SkillWeights: model.SkillWeights{1, 2, 3},
		},
		Runner:    "simple",
		Languages: []string{"java", "py"},
	}.Save(ctx)

	model.Challenge{
		Assignment: model.Assignment{
			Name:         "Sequential test",
			Description:  "Description of sequential challenge",
			Instructions: "Instructions of sequential challenge",
			Duration:     time.Hour,
			Endpoints: model.Endpoints{
				WebInterface: "sequential-challenge",
			},
		},
		Tasks: []*datastore.Key{taskOne, taskTwo, taskThree},
	}.SaveWithParent(ctx, coduno)

}