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"}}