add sorting; implement sort criteria in default repo ; adding html header
This commit is contained in:
@@ -9,14 +9,19 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type articleDateOrder struct {}
|
||||
func (ord articleDateOrder) Weight(a *model.Article) int {
|
||||
return int(a.PublishDate.Unix()) * -1
|
||||
}
|
||||
|
||||
func index(w http.ResponseWriter, req *http.Request) {
|
||||
fds, _ := data.NewFileDatastore("./persistence/spiegel100.json")
|
||||
|
||||
repo, _ := data.NewDefaultRepository[*model.Article](fds, "article")
|
||||
articles, _ := repo.GetAll()
|
||||
articles, _ := repo.GetByCriteria(articleDateOrder{})
|
||||
|
||||
t := template.Must(template.ParseFiles("templates/article.html", "templates/layout.html"))
|
||||
_ = t.ExecuteTemplate(w, "base", articles)
|
||||
_ = t.ExecuteTemplate(w, "base", articles[:10])
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user