From ceab7281e92586a26d6c1396a4ae05314e78330c Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 17 Mar 2024 09:15:37 +0100 Subject: [PATCH] Now everyone only sees their own rejected articles --- cmd/view/articles.go | 24 ++++++++++++++++++++++-- web/templates/rejected-articles.html | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cmd/view/articles.go b/cmd/view/articles.go index dd7ee65..05509c2 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -140,16 +140,36 @@ func ShowUnpublishedArticles(db *model.DB) http.HandlerFunc { func ShowRejectedArticles(db *model.DB, s *control.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - rejectedArticles, err := db.GetCertainArticles(false, true) + type htmlData struct { + RejectedArticles []*model.Article + MyIDs map[int64]bool + } + data := new(htmlData) + + session, err := s.Get(r, "cookie") if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return } + data.RejectedArticles, err = db.GetCertainArticles(false, true) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data.MyIDs = make(map[int64]bool) + for _, article := range data.RejectedArticles { + if article.AuthorID == session.Values["id"].(int64) { + data.MyIDs[article.ID] = true + } + } + tmpl, err := template.ParseFiles("web/templates/rejected-articles.html") tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", rejectedArticles) + tmpl.ExecuteTemplate(w, "page-content", data) } } diff --git a/web/templates/rejected-articles.html b/web/templates/rejected-articles.html index 934a973..44c43e9 100644 --- a/web/templates/rejected-articles.html +++ b/web/templates/rejected-articles.html @@ -1,9 +1,11 @@ {{define "page-content"}}
- {{range .}} + {{range .RejectedArticles}} + {{if index $.MyIDs .ID}} {{end}} + {{end}}