/
record-repository.go
53 lines (42 loc) · 1.31 KB
/
record-repository.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package repositories
import (
"github.com/jackc/pgtype"
"github.com/mitchellh/mapstructure"
"github.com/jeanguel/street-critters/api/config"
"github.com/jeanguel/street-critters/api/models"
)
func GetAllRecords(searchQuery *models.SearchQuery) ([]models.Record, error) {
results := []models.Record{}
params := []interface{}{
searchQuery.Amount,
searchQuery.GetOffset(),
}
rawResult, err := config.ExecPSQLFunc("report.get_all_records", params...)
if err != nil {
return results, err
}
err = mapstructure.Decode(rawResult, &results)
for i, result := range results {
results[i].FloatGeopoint = [2]float64{result.Geopoint.P.X, result.Geopoint.P.Y}
}
return results, err
}
func GetRecordsByBoundingBox(startLongitude, startLatitude, endLongitude, endLatitude float64) ([]models.Record, error) {
results := []models.Record{}
boundingBox := pgtype.Box{
P: [2]pgtype.Vec2{
{X: startLongitude, Y: startLatitude},
{X: endLongitude, Y: endLatitude},
},
Status: pgtype.Present,
}
rawResult, err := config.ExecPSQLFunc("report.get_records_by_bounding_box", boundingBox)
if err != nil {
return results, err
}
err = mapstructure.Decode(rawResult, &results)
for i, result := range results {
results[i].FloatGeopoint = [2]float64{result.Geopoint.P.X, result.Geopoint.P.Y}
}
return results, err
}