Exemple #1
0
func handlerPostsIndex(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	boardID, _ := strconv.Atoi(params.ByName("board_id"))
	var board Board
	request := db.First(&board, boardID)
	if request.Error == gorm.RecordNotFound {
		http.NotFound(w, r)
		return
	}
	renderPostsIndex(w, board)
}
Exemple #2
0
func handlerPostSave(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	boardID, _ := strconv.Atoi(params.ByName("board_id"))
	postID, _ := strconv.Atoi(params.ByName("id"))
	post := Post{
		Title:   r.FormValue("title"),
		Body:    r.FormValue("body"),
		BoardID: boardID,
		PostID:  postID,
	}
	db.Create(&post)
	log.Print(post)
	http.Redirect(w, r, ("/boards/" + strconv.Itoa(boardID) + "/posts/" + strconv.Itoa(postID)), 302)
}
Exemple #3
0
func handlerShow(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	postID, _ := strconv.Atoi(params.ByName("id"))
	renderShow(w, postID)
}