Esempio n. 1
0
func AddTopic(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error
	var topic forum.Topic

	if topic.GroupID, err = strconv.Atoi(req.FormValue("groupID")); err != nil {
		apierror.GenerateError("Trouble getting forum group ID for new topic", err, rw, req)
	}

	if req.FormValue("closed") != "" {
		if topic.Closed, err = strconv.ParseBool(req.FormValue("closed")); err != nil {
			apierror.GenerateError("Trouble adding forum topic -- boolean closed parameter is invalid", err, rw, req)
		}
	}

	topic.Name = req.FormValue("name")
	topic.Description = req.FormValue("description")
	topic.Image = req.FormValue("image")
	topic.Active = true

	if err = topic.Add(); err != nil {
		apierror.GenerateError("Trouble adding forum topic", err, rw, req)
	}

	return encoding.Must(enc.Encode(topic))
}