25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.2 KiB

  1. package service
  2. import (
  3. "context"
  4. "github.com/AFASystems/presence/internal/pkg/common/appcontext"
  5. "github.com/AFASystems/presence/internal/pkg/model"
  6. )
  7. func LocationToBeaconService(msg model.HTTPLocation, appState *appcontext.AppState, ctx context.Context) error {
  8. id := msg.ID
  9. beacon, ok := appState.GetHTTPResult(id)
  10. if !ok {
  11. appState.UpdateHTTPResult(id, model.HTTPResult{ID: id, Position: msg.Location, Distance: msg.Distance, LastSeen: msg.LastSeen, PreviousConfidentLocation: msg.PreviousConfidentLocation})
  12. } else {
  13. beacon.ID = id
  14. beacon.Position = msg.Location
  15. beacon.Distance = msg.Distance
  16. beacon.LastSeen = msg.LastSeen
  17. beacon.PreviousConfidentLocation = msg.PreviousConfidentLocation
  18. appState.UpdateHTTPResult(id, beacon)
  19. }
  20. return nil
  21. }
  22. func EventToBeaconService(msg model.BeaconEvent, appState *appcontext.AppState, ctx context.Context) error {
  23. id := msg.ID
  24. beacon, ok := appState.GetHTTPResult(id)
  25. if !ok {
  26. appState.UpdateHTTPResult(id, model.HTTPResult{ID: id, BeaconType: msg.Type, Battery: int64(msg.Battery), Event: msg.Event})
  27. } else {
  28. beacon.ID = id
  29. beacon.BeaconType = msg.Type
  30. beacon.Battery = int64(msg.Battery)
  31. beacon.Event = msg.Event
  32. appState.UpdateHTTPResult(id, beacon)
  33. }
  34. return nil
  35. }