Now everyone only sees their own rejected articles

This commit is contained in:
Jason Streifling 2024-03-17 09:15:37 +01:00
parent 450dd79e51
commit ceab7281e9
2 changed files with 25 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -1,9 +1,11 @@
{{define "page-content"}}
<form>
{{range .}}
{{range .RejectedArticles}}
{{if index $.MyIDs .ID}}
<input required id="{{.ID}}" name="id" type="radio" value="{{.ID}}" />
<label for="{{.ID}}">{{.Title}}</label>
{{end}}
{{end}}
<input type="submit" value="Auswählen" hx-post="/review-rejected-article/" hx-target="#page-content" />
</form>
<button hx-get="/hub/" hx-target="#page-content">Zurück</button>