Esempio n. 1
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)
}
Esempio n. 2
0
func updateProjectHandler(w http.ResponseWriter, r *http.Request) {
	//s := redis_session.Session(w, r)
	r.ParseForm()
	//currentUser := user.FindUser(s.Get("Email"))
	castsAttendees := r.Form["castEmail[]"]
	//fmt.Println(castsAttendees)
	castRoles := r.Form["castRole[]"]
	//fmt.Println(castRoles)
	projectId := r.URL.Query().Get("id")
	var castContainer []*project.Cast
	var newCast *project.Cast
	for i := 0; i < len(castsAttendees); i++ {
		castId := bson.NewObjectId()
		//fmt.Println(castId)
		castUser := user.FindUser(castsAttendees[i])
		//fmt.Println(castUser)
		newCast = project.NewCast(castUser, castRoles[i], castId)
		project.InsertCast(newCast)
		castContainer = append(castContainer, newCast)
	}
	editedProject := project.ChangedProject(r.FormValue("title"), r.FormValue("url"), r.FormValue("shortDescription"), r.FormValue("description"), castContainer)
	project.UpdateProject(projectId, editedProject)

	urlParts := []string{"/projects/?id=", projectId, "#success"}
	url := strings.Join(urlParts, "")
	http.Redirect(w, r, url, http.StatusTemporaryRedirect)
}
Esempio n. 3
0
//api call for submitting project
func submitProjectHandler(w http.ResponseWriter, r *http.Request) {
	//data := setDefaultData(w, r)
	//submission := make(map[string]interface{})
	// **TOP
	s := redis_session.Session(w, r)
	currentUser := user.FindUser(s.Get("Email"))

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

	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)
	}

	projectId := bson.NewObjectId()
	fmt.Println("ID :::: ", projectId)
	//s := redis_session.Session(w, r)
	newProject := project.NewProject(r.FormValue("title"), r.FormValue("url"), r.FormValue("shortDescription"), r.FormValue("description"), castContainer, currentUser, projectId)
	//fmt.Println("new project: ", newProject.Id)
	project.InsertProject(newProject)

	urlParts := []string{"/projects/?id=", projectId.Hex()}
	url := strings.Join(urlParts, "")
	// redirect to project page
	http.Redirect(w, r, url, http.StatusTemporaryRedirect)
}