From cc8693ffaf289aaa316a26da7e11a85f2c1d3820 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 19 Jan 2025 09:34:03 +0100 Subject: [PATCH] Serve article clicks via uuid --- cmd/calls/articles.go | 6 ++---- cmd/main.go | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/calls/articles.go b/cmd/calls/articles.go index e75a56a..3e46703 100644 --- a/cmd/calls/articles.go +++ b/cmd/calls/articles.go @@ -5,7 +5,6 @@ import ( "log" "net/http" "os" - "strconv" "github.com/google/uuid" b "streifling.com/jason/cpolis/cmd/backend" @@ -88,15 +87,14 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc { func ServeClicks(db *b.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - idString := r.PathValue("id") - id, err := strconv.ParseInt(idString, 10, 64) + uuid, err := uuid.Parse(r.PathValue("uuid")) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return } - article, err := db.GetArticle(id) + article, err := db.GetArticleByUUID(uuid) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/cmd/main.go b/cmd/main.go index c5aab1c..7c047bd 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -53,7 +53,7 @@ func main() { mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, sessions)) mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewArticle(config, db, sessions, "publish", "Artikel veröffentlichen", "Veröffentlichen")) mux.HandleFunc("GET /article/serve/{uuid}", c.ServeArticle(config, db)) - mux.HandleFunc("GET /article/serve/{id}/clicks", c.ServeClicks(db)) + mux.HandleFunc("GET /article/serve/{uuid}/clicks", c.ServeClicks(db)) mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, sessions)) mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config)) mux.HandleFunc("GET /hub", f.ShowHub(config, db, sessions))