From 83da3c3823f4fa6c5697120783920f5ec9f34ec8 Mon Sep 17 00:00:00 2001 From: Mads Mogensen Date: Thu, 7 Dec 2023 09:15:01 +0100 Subject: [PATCH] Fix crash when getting measurements --- .../Controllers/MeasurementController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CentralHub.Api/Controllers/MeasurementController.cs b/CentralHub.Api/Controllers/MeasurementController.cs index 14e7323..e55f7ab 100644 --- a/CentralHub.Api/Controllers/MeasurementController.cs +++ b/CentralHub.Api/Controllers/MeasurementController.cs @@ -93,8 +93,18 @@ private static IReadOnlyList CreateMeasurements(IReadOnl .Where(am => am.EndTime > (DateTime.UtcNow - TimeSpan.FromDays(1))) .ToImmutableArray(); - var bluetoothCalibrationNumber = recentAggregatedMeasurements.Min(am => am.BluetoothCount); - var wifiCalibrationNumber = recentAggregatedMeasurements.Min(am => am.WifiCount); + int bluetoothCalibrationNumber; + int wifiCalibrationNumber; + if (recentAggregatedMeasurements.Any()) + { + bluetoothCalibrationNumber = recentAggregatedMeasurements.Min(am => am.BluetoothCount); + wifiCalibrationNumber = recentAggregatedMeasurements.Min(am => am.WifiCount); + } + else + { + bluetoothCalibrationNumber = 0; + wifiCalibrationNumber = 0; + } return aggregatedMeasurements.Select(am => new AggregatedMeasurements( am.AggregatedMeasurementDtoId,