Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Commit f6950c4

Browse files
cleanup + start and end params for locations_archive
1 parent d2a7654 commit f6950c4

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ The directory structure of a generated Revel application:
4040
* The [Revel guides](http://revel.github.io/manual/index.html).
4141
* The [Revel sample apps](http://revel.github.io/examples/index.html).
4242
* The [API documentation](https://godoc.org/github.com/revel/revel).
43-

app/controllers/locationsarchive.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package controllers
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/Jeffail/gabs"
@@ -13,9 +12,20 @@ type LocationsArchive struct {
1312
}
1413

1514
func (c LocationsArchive) List() revel.Result {
15+
// purge old data
16+
DB.Exec(`DELETE FROM locations_archive
17+
WHERE created < (NOW() - INTERVAL '48 HOURS')`)
18+
19+
startEpoch := c.Params.Query.Get("start")
20+
endEpoch := c.Params.Query.Get("end")
21+
22+
// retrieve archived data
1623
rows, err := DB.Raw(`SELECT device, created, longitude, latitude
1724
FROM locations_archive
18-
WHERE created BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()`).Rows()
25+
WHERE
26+
created BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()
27+
AND
28+
created BETWEEN TO_TIMESTAMP(?) AND TO_TIMESTAMP(?)`, startEpoch, endEpoch).Rows()
1929

2030
if err != nil {
2131
return c.RenderError(err)
@@ -32,8 +42,6 @@ func (c LocationsArchive) List() revel.Result {
3242

3343
rows.Scan(&device, &created, &longitude, &latitude)
3444

35-
fmt.Println(created)
36-
3745
if !jsonObj.Exists(device) {
3846
jsonObj.Array(device)
3947
}

0 commit comments

Comments
 (0)