diff options
Diffstat (limited to 'src/post/routes.go')
| -rw-r--r-- | src/post/routes.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/post/routes.go b/src/post/routes.go index 9932004..09457d3 100644 --- a/src/post/routes.go +++ b/src/post/routes.go @@ -1,10 +1,13 @@ package post import ( + "fmt" "log" "net/http" - "github.com/volatiletech/sqlboiler/boil" + "github.com/go-chi/chi/v5" + "github.com/volatiletech/sqlboiler/v4/boil" + "gitlab.com/alexkavon/newsstand/src/models" "gitlab.com/alexkavon/newsstand/src/server" "gitlab.com/alexkavon/newsstand/src/sessions" ) @@ -17,6 +20,19 @@ var Routes = server.Routes{ HandlerFunc: Create, Middlewares: server.NewMiddlewares(sessions.AuthSession), }, + server.Route{ + Name: "Store", + Method: "POST", + Path: "/p", + HandlerFunc: Store, + Middlewares: server.NewMiddlewares(sessions.AuthSession), + }, + server.Route{ + Name: "Get", + Method: "GET", + Path: "/p/{:id}", + HandlerFunc: Get, + }, } func Create(s *server.Server) http.HandlerFunc { @@ -32,12 +48,23 @@ func Store(s *server.Server) http.HandlerFunc { post.Url = r.PostFormValue("url") post.Description = r.PostFormValue("description") + // validate post + // process post, look for spamminess, bad url + // match post title with url title if provided + // check title for tags: Ask NY, subway, crime, culture err := post.Insert(r.Context(), s.Db.ToSqlDb(), boil.Infer()) if err != nil { log.Fatal("Insert Error", err) } // increment user points maybe + // redirect to new post + http.Redirect(w, r, fmt.Sprintf("p/%d", post.ID), http.StatusSeeOther) + } +} +func Get(s *server.Server) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + post := models.FindPost(r.Context(), s.Db.ToSqlDb(), chi.URLParam(r, "id")) } } |
