Serve articles via uuid
This commit is contained in:
parent
52b5dbf2c7
commit
9c0c7361a0
@ -115,6 +115,32 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
|||||||
return article, nil
|
return article, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetArticleByUUID(u uuid.UUID) (*Article, error) {
|
||||||
|
query := `
|
||||||
|
SELECT id, title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated
|
||||||
|
FROM articles
|
||||||
|
WHERE uuid = ?
|
||||||
|
`
|
||||||
|
row := db.QueryRow(query, u.String())
|
||||||
|
|
||||||
|
article := new(Article)
|
||||||
|
var created []byte
|
||||||
|
var uuidString string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if err := row.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
||||||
|
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
article.UUID = u
|
||||||
|
article.Created, err = time.Parse("2006-01-02 15:04:05", string(created))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return article, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, error) {
|
func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, error) {
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
SELECT id, title, created, banner_link, summary, creator_id, issue_id, clicks, published, rejected, is_in_issue, auto_generated, uuid
|
SELECT id, title, created, banner_link, summary, creator_id, issue_id, clicks, published, rejected, is_in_issue, auto_generated, uuid
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,15 +38,15 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
idString := r.PathValue("id")
|
uuidString := r.PathValue("uuid")
|
||||||
id, err := strconv.ParseInt(idString, 10, 64)
|
uuid, err := uuid.Parse(uuidString)
|
||||||
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)
|
||||||
|
@ -52,7 +52,7 @@ func main() {
|
|||||||
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, sessions, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, sessions, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
||||||
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/{id}", 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/{id}/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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user