diff --git a/main.go b/main.go index 9f9559a..dac6aa8 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,8 @@ func main() { } func handleNewWeatherData(wd storage.WeatherData) error { - if !config.AllowUnregisteredSensors() && !sensorRegistry.ExistSensorId(wd.SensorId) { + _, couldResolve := sensorRegistry.ResolveSensorById(wd.SensorId) + if !config.AllowUnregisteredSensors() && !couldResolve { return errors.New("sensor have to be registered") } weatherStorage.Save(wd) diff --git a/storage/inmemory-storage.go b/storage/inmemory-storage.go index 9e00e14..4bacde8 100644 --- a/storage/inmemory-storage.go +++ b/storage/inmemory-storage.go @@ -35,13 +35,13 @@ func (registry *inmemorySensorRegistry) ExistSensorName(name string) bool { return false } -func (registry *inmemorySensorRegistry) ExistSensorId(sensorId uuid.UUID) bool { +func (registry *inmemorySensorRegistry) ResolveSensorById(sensorId uuid.UUID) (*WeatherSensor, bool) { for _, s := range registry.weatherSensors { if s.Id == sensorId { - return true + return s, true } } - return false + return nil, false } func (registry *inmemorySensorRegistry) ExistSensor(sensor *WeatherSensor) bool { diff --git a/storage/weather-data.go b/storage/weather-data.go index e6d3728..658fb1d 100644 --- a/storage/weather-data.go +++ b/storage/weather-data.go @@ -17,7 +17,7 @@ type WeatherStorage interface { type SensorRegistry interface { RegisterSensorByName(string) (*WeatherSensor, error) ExistSensor(*WeatherSensor) bool - ExistSensorId(uuid.UUID) bool + ResolveSensorById(uuid.UUID) (*WeatherSensor, bool) GetSensors() []*WeatherSensor Close() error }