aboutsummaryrefslogtreecommitdiff
blob: db5f237d6c8a44f5956e28d1501da94102de78f0 (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
36
37
38
39
package list

import (
	"archives/pkg/cache"
	"archives/pkg/database"
	"archives/pkg/models"
	"net/http"
	"strings"
)

func Show(w http.ResponseWriter, r *http.Request) {
	listName := strings.ReplaceAll(r.URL.Path, "/", "")
	templateData := cache.Get("/" + listName + "/")
	if templateData == nil {
		http.NotFound(w,r)
		return
	}
	renderShowTemplate(w, listName, templateData)
}


func ComputeShowTemplateData(listName string) interface{} {
	var res []struct {
		CombinedDate string
		MessageCount int
	}
	err := database.DBCon.Model((*models.Message)(nil)).
		Where("list = ?", listName).
		ColumnExpr("to_char(date, 'YYYY-MM') AS combined_date").
		ColumnExpr("count(*) AS message_count").
		Group("combined_date").
		Order("combined_date DESC").
		Select(&res)

	if err != nil {
		return nil
	}
	return res
}