diff options
Diffstat (limited to 'src/post/routes.go')
| -rw-r--r-- | src/post/routes.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/post/routes.go b/src/post/routes.go new file mode 100644 index 0000000..9932004 --- /dev/null +++ b/src/post/routes.go @@ -0,0 +1,43 @@ +package post + +import ( + "log" + "net/http" + + "github.com/volatiletech/sqlboiler/boil" + "gitlab.com/alexkavon/newsstand/src/server" + "gitlab.com/alexkavon/newsstand/src/sessions" +) + +var Routes = server.Routes{ + server.Route{ + Name: "Create", + Method: "GET", + Path: "/p/create", + HandlerFunc: Create, + Middlewares: server.NewMiddlewares(sessions.AuthSession), + }, +} + +func Create(s *server.Server) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + s.Ui.Render(w, r, "post/create", nil) + } +} + +func Store(s *server.Server) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var post models.Post + post.Title = r.PostFormValue("title") + post.Url = r.PostFormValue("url") + post.Description = r.PostFormValue("description") + + err := post.Insert(r.Context(), s.Db.ToSqlDb(), boil.Infer()) + if err != nil { + log.Fatal("Insert Error", err) + } + + // increment user points maybe + + } +} |
