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