diff --git a/.gitignore b/.gitignore index 834ab10..f052f41 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ main **/*.log -ROADMAP.md \ No newline at end of file +ROADMAP.md +docs/architectural-concerns.md \ No newline at end of file diff --git a/cmd/server/main.go b/cmd/server/main.go index 92d3e69..2798ac3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -130,12 +130,22 @@ eventLoop: case <-ctx.Done(): break eventLoop case msg := <-chLoc: + if msg.ID == "" { + fmt.Println("Received message with empty ID, skipping...") + continue + } id := msg.ID + + fmt.Println("id: ", id) if err := db.First(&model.Tracker{}, "id = ?", id).Error; err != nil { fmt.Printf("Location event for untracked beacon: %s\n", id) continue } + var results []model.TrackerZones + db.Where("tracker = ?", id).Find(&results) + fmt.Printf("%v", results) + if err := db.Updates(&model.Tracker{ID: id, Location: msg.Location, Distance: msg.Distance}).Error; err != nil { fmt.Println("Error in saving distance for beacon: ", err) continue diff --git a/internal/pkg/controller/trackerzones_controller.go b/internal/pkg/controller/trackerzones_controller.go index ece42ad..f03a213 100644 --- a/internal/pkg/controller/trackerzones_controller.go +++ b/internal/pkg/controller/trackerzones_controller.go @@ -9,7 +9,6 @@ import ( "gorm.io/gorm" ) -// controller/tracker_controller.go func TrackerZoneAddController(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var tz model.TrackerZones diff --git a/internal/pkg/model/tracker_zones.go b/internal/pkg/model/tracker_zones.go index 4caba39..0202a8e 100644 --- a/internal/pkg/model/tracker_zones.go +++ b/internal/pkg/model/tracker_zones.go @@ -3,7 +3,7 @@ package model type TrackerZones struct { ID string `json:"id" gorm:"primaryKey"` ZoneList []string `json:"zoneList" gorm:"serializer:json"` - Tracker string `json:"tracker"` + Tracker string `json:"tracker" gorm:"index"` Days string `json:"days"` Time string `json:"time"` }