Example #1
0
func submitTeamHandler(w http.ResponseWriter, r *http.Request) {
	//data := setDefaultData(w, r)
	//submission := make(map[string]interface{})
	// **TOP
	r.ParseForm()
	teamMembers := r.Form["teamEmails"]

	newContest := role.FindContests()
	currentContest := role.FindContest(newContest[0].Id.Hex())

	teamContainer := make([]*user.User, 0)
	for i := 0; i < len(teamMembers); i++ {
		newUser := user.FindUser(teamMembers[i])
		teamContainer = append(teamContainer, newUser)
	}

	teamId := bson.NewObjectId()
	//s := redis_session.Session(w, r)

	// ****** CLEANING ********
	newTeam := role.NewTeam(teamContainer, r.FormValue("teamName"), r.FormValue("motto"), teamId)

	role.InsertNewTeam(newTeam)

	currentContest.InsertTeam(newTeam)

	//data["contests"] = currentContest
	http.Redirect(w, r, "/teams/browse", http.StatusTemporaryRedirect)
}
Example #2
0
func submitContestProjectHandler(w http.ResponseWriter, r *http.Request) {
	s := redis_session.Session(w, r)
	currentUser := user.FindUser(s.Get("Email"))

	r.ParseForm()
	castsAttendees := r.Form["castEmail[]"]
	castRoles := r.Form["castRole[]"]

	newContest := role.FindContests()
	currentContest := newContest[0]

	var castContainer []*project.Cast
	var newCast *project.Cast
	for i := 0; i < len(castsAttendees); i++ {
		castId := bson.NewObjectId()
		castUser := user.FindUser(castsAttendees[i])
		newCast = project.NewCast(castUser, castRoles[i], castId)
		project.InsertCast(newCast)
		castContainer = append(castContainer, newCast)
	}

	description := []string{r.FormValue("teamName") + ": \n", r.FormValue("description")}
	combinedDescription := strings.Join(description, "")

	projectId := bson.NewObjectId()
	newProject := project.NewContestProject(r.FormValue("title"), r.FormValue("url"), r.FormValue("shortDescription"), combinedDescription, castContainer, currentUser, projectId, currentContest)
	project.InsertProject(newProject)

	urlParts := []string{"/projects/?id=", projectId.Hex()}
	url := strings.Join(urlParts, "")
	http.Redirect(w, r, url, http.StatusTemporaryRedirect)
}
Example #3
0
func browseTeamsHandler(w http.ResponseWriter, r *http.Request) {
	data := setDefaultData(w, r)

	newContest := role.FindContests()
	contestList := role.FindContest(newContest[0].Id.Hex())

	fmt.Println(contestList)

	data["contests"] = contestList

	display(w, "browseTeams", &Page{Title: "Teams", Data: data})
}
Example #4
0
func contestMainHandler(w http.ResponseWriter, r *http.Request) {
	s := redis_session.Session(w, r)
	currentUser := user.FindUser(s.Get("Email"))
	data := setDefaultData(w, r)

	// newContest := role.FindContests()
	// currentContest := role.FindContest(newContest[0].Id.Hex())

	contestId := r.URL.Query().Get("id")
	if contestId == "" {
		newContest := role.FindContests()
		contestId = newContest[0].Id.Hex()
	}
	contest := role.FindContest(contestId)
	data["contest"] = contest
	data["user"] = currentUser
	display(w, "viewContest", &Page{Title: "Contest", Data: data})
}