More output on the home page
Build and copy to prod / build-and-copy (push) Successful in 32s

This commit is contained in:
Lewis Dale committed 2024-05-13 07:37:11 +01:00
1 parent 72122553dd
commit a7a55b6a90
3 files changed
+61 -2

No files matched your search

+40
View File
@@ -101,3 +101,43 @@ func List(db *sql.DB) []PingResponse {
return pings
}
type SiteResponse struct {
created_at string
Name string
Url string
Pings []Ping
}
func ListGroupedBySite(db *sql.DB) []SiteResponse {
responses := make([]SiteResponse, 0)
for _, site := range sites.List(db) {
s := SiteResponse{Url: site.Url, Name: site.Name, created_at: site.Created_at}
s.Pings = listForSite(db, site)
responses = append(responses, s)
}
return responses
}
func listForSite(db *sql.DB, site sites.Site) []Ping {
rows, err := db.Query(`SELECT ping.timestamp, ping.status FROM ping WHERE site = ? ORDER BY timestamp DESC`, site.Url)
if err != nil {
panic(err)
}
defer rows.Close()
pings := make([]Ping, 0)
for rows.Next() {
p := Ping{}
rows.Scan(&p.Timestamp, &p.Status)
p.Site = site
pings = append(pings, p)
}
return pings
}