aboutsummaryrefslogtreecommitdiff
blob: d1adfe249e6c2ced809f00d42f2d0ca9eb61eb2f (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
34
35
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/threads.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).
		Where(`starts_thread = TRUE`).
		Where("not date is null").
		OrderExpr("date DESC").
		Limit(n).
		Select()

	return recentMessages, err
}