This commit is contained in:
1 parent
72122553dd
commit
a7a55b6a90
3 files changed
+61
-2
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user