2 Révisions

Auteur SHA1 Message Date
  Blaz Smehov 355a0c9b52 fix: floors are now persisted in the db il y a 1 semaine
  Blaz Smehov a71e69ac3a fix: various fixes il y a 1 semaine
9 fichiers modifiés avec 30 ajouts et 10 suppressions
  1. BIN
      bridge
  2. BIN
      decoder
  3. +2
    -1
      internal/app/server/app.go
  4. +15
    -0
      internal/pkg/apiclient/data.go
  5. +4
    -0
      internal/pkg/apiclient/updatedb.go
  6. +7
    -7
      internal/pkg/model/floor.go
  7. +2
    -2
      internal/pkg/service/beacon_service.go
  8. BIN
      location
  9. BIN
      server

BIN
bridge Voir le fichier


BIN
decoder Voir le fichier


+ 2
- 1
internal/app/server/app.go Voir le fichier

@@ -19,6 +19,7 @@ import (
"github.com/AFASystems/presence/internal/pkg/model"
"github.com/AFASystems/presence/internal/pkg/service"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)

// ServerApp holds dependencies and state for the server service.
@@ -87,7 +88,7 @@ func (a *ServerApp) Init(ctx context.Context) error {
}

for _, c := range configs {
a.DB.Create(&c)
a.DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&c)
}
a.DB.Find(&configs)
for _, c := range configs {


+ 15
- 0
internal/pkg/apiclient/data.go Voir le fichier

@@ -54,6 +54,21 @@ func GetTrackerZones(token string, client *http.Client, cfg *config.Config) ([]m
return i, nil
}

func GetFloors(token string, client *http.Client, cfg *config.Config) ([]model.Floor, error) {
res, err := getRequest(token, "getFloors", client, cfg)
if err != nil {
return []model.Floor{}, err
}

var i []model.Floor
err = json.NewDecoder(res.Body).Decode(&i)
if err != nil {
return []model.Floor{}, err
}

return i, nil
}

func GetZones(token string, client *http.Client, cfg *config.Config) ([]model.Zone, error) {
res, err := getRequest(token, "getZones", client, cfg)
if err != nil {


+ 4
- 0
internal/pkg/apiclient/updatedb.go Voir le fichier

@@ -52,6 +52,10 @@ func UpdateDB(db *gorm.DB, ctx context.Context, cfg *config.Config, writer *kafk
syncTable(db, gateways)
}

if floors, err := GetFloors(token, client, cfg); err == nil {
syncTable(db, floors)
}

if zones, err := GetZones(token, client, cfg); err == nil {
syncTable(db, zones)
}


+ 7
- 7
internal/pkg/model/floor.go Voir le fichier

@@ -1,11 +1,11 @@
package model

type Floor struct {
ID string `gorm:"unique;primaryKey"`
Name string `json:"name"`
FloorNumber int `json:"floornumber"`
Image string `json:"image"`
Description string `json:"description"`
Scale int `json:"scale"`
Building string `json:"building"`
ID string `gorm:"unique;primaryKey"`
Name string `json:"name"`
FloorNumber int `json:"floornumber"`
Image string `json:"image"`
Description string `json:"description"`
Scale float32 `json:"scale"`
Building string `json:"building"`
}

+ 2
- 2
internal/pkg/service/beacon_service.go Voir le fichier

@@ -151,9 +151,9 @@ func LocationToBeaconServiceAI(msg model.HTTPLocation, db *gorm.DB, writer *kafk

func SendAlert(trackerId, alertType string, writer *kafka.Writer, ctx context.Context, db *gorm.DB) {
var existingAlert model.Alert
result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").First(&existingAlert)
result := db.Select("status").Where("tracker_id = ? AND type = ?", trackerId, alertType).Order("timestamp DESC").Limit(1).Find(&existingAlert)

if result.Error == gorm.ErrRecordNotFound || existingAlert.Status == "resolved" {
if result.RowsAffected == 0 || existingAlert.Status == "resolved" {
alert := model.Alert{
ID: uuid.New().String(),
TrackerID: trackerId,


BIN
location Voir le fichier


BIN
server Voir le fichier


Chargement…
Annuler
Enregistrer