Exemplo n.º 1
0
Arquivo: view.go Projeto: amaudy/Gooo
func SaveHandler(w http.ResponseWriter, r *http.Request, title string) {
	content := r.FormValue("content")
	p := &model.Post{Title: title, Content: content, UserId: 1, Published: true, Created: time.Now(), Modified: time.Now()}
	p.Title = "lol"
	atts := introspection.GetStructValues(&p)
	model.InsertIntoDB(atts)
	ctx := map[string]interface{}{"post": introspection.ConvertToMap(p)}
	RenderTemplate(w, "post", ctx)
}
Exemplo n.º 2
0
func NewPostHandler(w http.ResponseWriter, r *http.Request) {
	title := r.FormValue("title")
	body := r.FormValue("content")
	userId, err := strconv.Atoi(r.FormValue("userId"))
	if err != nil {
		userId = 0
		//TODO: implement user model
	}
	published := true
	p := model.Post{0, title, body, userId, published, time.Now(), time.Now()}
	atts := introspection.GetStructValues(&p)
	model.InsertIntoDB(atts)
	http.Redirect(w, r, "/", http.StatusFound)
}
Exemplo n.º 3
0
Arquivo: view.go Projeto: amaudy/Gooo
func HomeHandler(w http.ResponseWriter, r *http.Request, title string) {
	db := model.OpenConn()
	model.TestEmptyDB(db)
	var p model.Post = model.Post{model.M, 2, "Hello World", "whats up yo", 1, true, time.Now(), time.Now()}
	var p2 model.Post = model.Post{model.M, 2, "Test2", "another test post please ignore", 1, true, time.Now(), time.Now()}
	fmt.Println(p.ModelName())
	atts := introspection.GetStructValues(&p)
	model.InsertIntoDB(atts)
	model.GetPosts(10)
	posts := map[string]interface{}{"p1": introspection.ConvertToMap(p), "p2": introspection.ConvertToMap(p2)}
	ctx := map[string]interface{}{"posts": posts}
	defer db.Close()
	//defer stmt.Close()
	RenderTemplate(w, "index", ctx)
}