aboutsummaryrefslogtreecommitdiff
blob: ec7d77fa09e4c7dadb63b79d9932815ed0a31d11 (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
// miscellaneous utility functions used for the landing page of the application

package home

import (
	"archives/pkg/database"
	"archives/pkg/models"
	"github.com/go-pg/pg/v10"
	"html/template"
	"net/http"
)

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

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

// utility methods

func getAllMessagesCount() int {
	var messsageCount int
	database.DBCon.Model((*models.Message)(nil)).QueryOne(pg.Scan(&messsageCount), `
		SELECT
			count(DISTINCT messages.message_id_field)
		FROM
			messages;
	`)
	return messsageCount
}