Only provide link in item instead of the entire article via content

This commit is contained in:
2024-08-30 15:17:14 +02:00
parent 10d8fceb77
commit be467521d9
4 changed files with 45 additions and 16 deletions

33
cmd/calls/articles.go Normal file
View File

@ -0,0 +1,33 @@
package calls
import (
"fmt"
"log"
"net/http"
"strconv"
b "streifling.com/jason/cpolis/cmd/backend"
)
func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if tokenIsVerified(w, r, c) {
idString := r.PathValue("id")
id, err := strconv.ParseInt(idString, 10, 64)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
article, err := db.GetArticle(id)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprint(w, article.Content)
}
}
}