Skip to content

Commit 7bd81f6

Browse files
committed
grab the history and forecast for field from reports
1 parent a239a06 commit 7bd81f6

10 files changed

Lines changed: 267 additions & 191 deletions

File tree

api/app.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
)
1212

1313
type App struct {
14-
cfg Config
15-
mongo *mongo.Client
16-
db *mongo.Database
17-
users *mongo.Collection
18-
fields *mongo.Collection
14+
cfg Config
15+
mongo *mongo.Client
16+
db *mongo.Database
17+
users *mongo.Collection
18+
fields *mongo.Collection
19+
reports *mongo.Collection
1920
}
2021

2122
func newApp(ctx context.Context, cfg Config) (*App, error) {
@@ -26,11 +27,12 @@ func newApp(ctx context.Context, cfg Config) (*App, error) {
2627
db := client.Database(cfg.MongoDB)
2728

2829
app := &App{
29-
cfg: cfg,
30-
mongo: client,
31-
db: db,
32-
users: db.Collection("users"),
33-
fields: db.Collection("fields"),
30+
cfg: cfg,
31+
mongo: client,
32+
db: db,
33+
users: db.Collection("users"),
34+
fields: db.Collection("fields"),
35+
reports: db.Collection("reports"),
3436
}
3537
// Indexes
3638
if _, err := app.users.Indexes().CreateOne(ctx, mongo.IndexModel{

api/config.go

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

33
import (
4-
"log"
54
"os"
65
)
76

@@ -21,9 +20,7 @@ func mustConfig() Config {
2120
JWTSecret: getenv("JWT_SECRET", "change_me"),
2221
Port: getenv("PORT", "8080"),
2322
}
24-
if cfg.JWTSecret == "change_me" {
25-
log.Println("[WARN] Using default JWT secret, override in .env for security")
26-
}
23+
2724
return cfg
2825
}
2926

api/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/go-chi/cors v1.2.2 // indirect
1010
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
1111
github.com/golang/snappy v0.0.4 // indirect
12+
github.com/joho/godotenv v1.5.1 // indirect
1213
github.com/klauspost/compress v1.16.7 // indirect
1314
github.com/montanaflynn/stats v0.7.1 // indirect
1415
github.com/xdg-go/pbkdf2 v1.0.0 // indirect

api/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9v
66
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
77
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
88
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
9+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
10+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
911
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
1012
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
1113
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=

0 commit comments

Comments
 (0)