aboutsummaryrefslogtreecommitdiff
blob: 5af1c2faccd3aad6ab754940c3f5a64a6b01f73c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package popular

import (
	"archives/pkg/database"
	"archives/pkg/models"
	"html/template"
	"net/http"
)

// renderIndexTemplate renders all templates used for the landing page
func renderPopularThreads(w http.ResponseWriter, templateData interface{}) {
	templates := template.Must(
		template.Must(
			template.New("Popular").
				ParseGlob("web/templates/layout/*.tmpl")).
			ParseGlob("web/templates/popular/*.tmpl"))

	templates.ExecuteTemplate(w, "threads.tmpl", templateData)
}

// utility methods

func GetPopularThreads(n int, date string) ([]*models.Message, error) {

	var recentMessages []*models.Message

	err := database.DBCon.Model(&recentMessages).
		OrderExpr("date DESC").
		Limit(n).
		Select()

	return recentMessages, err
}