|
- package service
-
- import (
- "context"
-
- "github.com/AFASystems/presence/internal/pkg/common/appcontext"
- "github.com/AFASystems/presence/internal/pkg/model"
- )
-
- func LocationToBeaconService(msg model.HTTPLocation, appState *appcontext.AppState, ctx context.Context) error {
- id := msg.ID
- beacon, ok := appState.GetHTTPResult(id)
- if !ok {
- appState.UpdateHTTPResult(id, model.HTTPResult{ID: id, Position: msg.Location, Distance: msg.Distance, LastSeen: msg.LastSeen, PreviousConfidentLocation: msg.PreviousConfidentLocation})
- } else {
- beacon.ID = id
- beacon.Position = msg.Location
- beacon.Distance = msg.Distance
- beacon.LastSeen = msg.LastSeen
- beacon.PreviousConfidentLocation = msg.PreviousConfidentLocation
- appState.UpdateHTTPResult(id, beacon)
- }
-
- return nil
- }
-
- func EventToBeaconService(msg model.BeaconEvent, appState *appcontext.AppState, ctx context.Context) error {
- id := msg.ID
- beacon, ok := appState.GetHTTPResult(id)
- if !ok {
- appState.UpdateHTTPResult(id, model.HTTPResult{ID: id, BeaconType: msg.Type, Battery: int64(msg.Battery), Event: msg.Event})
- } else {
- beacon.ID = id
- beacon.BeaconType = msg.Type
- beacon.Battery = int64(msg.Battery)
- beacon.Event = msg.Event
- appState.UpdateHTTPResult(id, beacon)
- }
-
- return nil
- }
|