Ejemplo n.º 1
0
func AddMember(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	userID := parser.Int(r.FormValue("userID"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if user.ID() != userID {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	if exists, err := store.MemberExists(projectID, userID); err != nil {
		response.ServerError(w, err)
		return
	} else if exists {
		response.OK(w, nil)
		return
	}

	if err := store.AddMember(projectID, userID); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
Ejemplo n.º 2
0
func CreateProject(w http.ResponseWriter, r *http.Request) {
	title := r.FormValue("title")
	if title == "" {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	tagline := r.FormValue("tagline")
	description := r.FormValue("description")

	// basic project info
	projectID, err := store.CreateProject(map[string]string{
		"authorID":    user.IDStr(),
		"title":       title,
		"tagline":     tagline,
		"description": description,
	})
	if err != nil {
		response.ServerError(w, err)
		return
	}

	var ok bool

	// add author to project user list
	if err = store.AddMember(projectID, user.ID()); err != nil {
		goto error
	}

	// image
	if ok, err = store.SaveProjectImage(w, r, projectID); err != nil || !ok {
		goto error
	}

	response.OK(w, projectID)
	return

error:
	if err := store.DeleteProject(projectID); err != nil {
		debug.Warn(err)
	}
	response.ServerError(w, err)
}