diff options
| author | Alexander Kavon <me+git@alexkavon.com> | 2024-01-22 21:30:19 -0500 |
|---|---|---|
| committer | Alexander Kavon <me+git@alexkavon.com> | 2024-01-22 21:30:19 -0500 |
| commit | 0cdc7a2e84ac5c460569a26a1dd8e3070cea487e (patch) | |
| tree | dd1f1f67e9dad99b21fd4d2f817beb846e1fe611 /src/post/routes.go | |
| parent | 481b799f9eced5432fdc0c66d2bf04226cdc723b (diff) | |
add posts table migration, add sqlboiler post model, post routes: create, store, get, post create ui template, remove email from user create route
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")) } } |
