Serve article clicks via uuid

This commit is contained in:
Jason Streifling 2025-01-19 09:34:03 +01:00
parent b8fd81a86d
commit cc8693ffaf
2 changed files with 3 additions and 5 deletions

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv"
"github.com/google/uuid" "github.com/google/uuid"
b "streifling.com/jason/cpolis/cmd/backend" 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 { func ServeClicks(db *b.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
idString := r.PathValue("id") uuid, err := uuid.Parse(r.PathValue("uuid"))
id, err := strconv.ParseInt(idString, 10, 64)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
article, err := db.GetArticle(id) article, err := db.GetArticleByUUID(uuid)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)

View File

@ -53,7 +53,7 @@ func main() {
mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, sessions)) 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/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/{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 /article/write", f.WriteArticle(config, db, sessions))
mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config)) mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config))
mux.HandleFunc("GET /hub", f.ShowHub(config, db, sessions)) mux.HandleFunc("GET /hub", f.ShowHub(config, db, sessions))