package app import ( "evening_detective_server/internal/modules/cudy" "evening_detective_server/internal/services/device_presence_service" proto "evening_detective_server/proto" "google.golang.org/protobuf/types/known/timestamppb" ) func deviceOptionalID(id *int32) *int { if id == nil { return nil } value := int(*id) return &value } func devicePublicID(id int) *int32 { if id == 0 { return nil } value := int32(id) return &value } func mapVenueDevices(devices []device_presence_service.Device) []*proto.VenueDevice { result := make([]*proto.VenueDevice, 0, len(devices)) for _, device := range devices { connections := make([]*proto.DeviceConnection, 0, len(device.Connections)) for _, connection := range device.Connections { connections = append(connections, &proto.DeviceConnection{ ID: connection.ID, FirstSeenAt: timestamppb.New(connection.FirstSeenAt), LastSeenAt: timestamppb.New(connection.LastSeenAt), IP: connection.IP, UserAgent: connection.UserAgent, Connected: connection.Connected, GameID: devicePublicID(connection.GameID), TeamID: devicePublicID(connection.TeamID), ScreenID: devicePublicID(connection.ScreenID), Kind: connection.Kind, }) } result = append(result, &proto.VenueDevice{ ID: device.ID, FirstSeenAt: timestamppb.New(device.FirstSeenAt), LastSeenAt: timestamppb.New(device.LastSeenAt), Connected: device.Connected, Connections: connections, }) } return result } func mapWiFi(snapshot cudy.Snapshot, stale bool) *proto.VenueWiFi { result := &proto.VenueWiFi{ Enabled: snapshot.Enabled, Stale: stale, HasError: snapshot.HasError, Clients: make([]*proto.WiFiClient, 0, len(snapshot.Clients)), } if !snapshot.CollectedAt.IsZero() { result.CollectedAt = timestamppb.New(snapshot.CollectedAt) } for _, client := range snapshot.Clients { var signal *int32 if client.Signal != nil { value := int32(*client.Signal) signal = &value } result.Clients = append(result.Clients, &proto.WiFiClient{ IP: client.IP, MAC: client.MAC, Band: client.Band, Signal: signal, }) } return result }