diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 44 |
1 files changed, 26 insertions, 18 deletions
@@ -1,5 +1,18 @@ package main +// ideez is a web application that allows people to post their ideas, it is meant to help +// brainstorming. + +// ToDo's +// - [ ] Create a Server out of this so you can run multiple instances +// - [ ] change CreatedAt to be Last Updated +// - [x] edit a post +// - [x] Store ideas to a file (encoder/gob) +// - [x] Change the date format printing +// - [x] outsource removing the posts to a separate cli tool +// - [x] Add a post +// - [x] Remove a post + import ( _ "embed" "encoding/gob" @@ -34,24 +47,15 @@ var ( var Ideas []Idea -// ToDo's -// - [ ] Create a Server out of this so you can run multiple instances -// - [x] edit a post -// - [x] Store ideas to a file (encoder/gob) -// - [x] Change the date format printing -// - [x] outsource removing the posts to a separate cli tool -// - [x] Add a post -// - [x] Remove a post - // Represents an idea -// CreatedAt is a formatted date string +// LastUpdated is a formatted date string // out of 5 rating of the idea // formatted time string with DateLayout type Idea struct { - Title string - Text string - Author string - CreatedAt string + Title string + Text string + Author string + LastUpdated string } // Data passed to the ideas_html template @@ -179,10 +183,10 @@ func main() { mux.HandleFunc("POST /idea/create/", func(w http.ResponseWriter, r *http.Request) { i := Idea{ - Title: r.FormValue("title"), - Author: r.FormValue("author"), - CreatedAt: time.Now().Format(DateLayout), - Text: r.FormValue("text"), + Title: r.FormValue("title"), + Author: r.FormValue("author"), + LastUpdated: time.Now().Format(DateLayout), + Text: r.FormValue("text"), } if i.Title == "" || i.Author == "" || i.Text == "" { tmpl.Execute(w, PageData{Ideas, "All fields are required"}) @@ -201,6 +205,8 @@ func main() { http.Redirect(w, r, "/ideas/", http.StatusMovedPermanently) }) + // A page to edit the idea, this page should lead to POST /idea/edit for confirming the edit. If + // the user cancels they should be redirected to the start page. This is done in the html. mux.HandleFunc("GET /idea/edit/", func(w http.ResponseWriter, r *http.Request) { t := r.URL.Query().Get("t") if t == "" { @@ -217,6 +223,7 @@ func main() { tmpl.Execute(w, PageData{Ideas, "No idea with title '" + t + "'."}) }) + // Perform the edit action on the idea mux.HandleFunc("POST /idea/edit/", func(w http.ResponseWriter, r *http.Request) { t := r.FormValue("title") if t == "" { @@ -237,6 +244,7 @@ func main() { i.Title = r.FormValue("title") i.Text = r.FormValue("text") + i.LastUpdated = time.Now().Format(DateLayout) log.Printf("Edited '%s'\n", i.Title) http.Redirect(w, r, "/ideas/", http.StatusMovedPermanently) |