Skip to content

Add gps coordinates to polling stations#1048

Merged
idormenco merged 3 commits intomainfrom
feature/add-gps-coordinates-to-polling-stations
Jan 25, 2026
Merged

Add gps coordinates to polling stations#1048
idormenco merged 3 commits intomainfrom
feature/add-gps-coordinates-to-polling-stations

Conversation

@idormenco
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Jan 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
votemonitor Ready Ready Preview, Comment Jan 25, 2026 7:57am

Request Review

@idormenco idormenco merged commit fca9811 into main Jan 25, 2026
4 checks passed
@idormenco idormenco deleted the feature/add-gps-coordinates-to-polling-stations branch January 25, 2026 08:02
Comment on lines +41 to +47
foreach (var groupedPollingStationId in groupedPollingStationIds)
{
if (groupedPollingStationId.numberOfDuplicates > 1)
{
AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where Note

This foreach loop
implicitly filters its target sequence
- consider filtering the sequence explicitly using '.Where(...)'.

Copilot Autofix

AI 11 days ago

In general, to fix this kind of issue you replace a foreach loop that uses an if guard (or continue) to filter items with a foreach over a filtered sequence using .Where(...). This makes the filtering explicit at the sequence level instead of inside the loop body.

For this specific code in api/src/Feature.PollingStations/Create/Endpoint.cs, the best fix is to add a .Where clause to groupedPollingStationIds so that the loop iterates only over those groups where numberOfDuplicates > 1. Concretely, change:

foreach (var groupedPollingStationId in groupedPollingStationIds)
{
    if (groupedPollingStationId.numberOfDuplicates > 1)
    {
        AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
    }
}

to:

foreach (var groupedPollingStationId in groupedPollingStationIds.Where(g => g.numberOfDuplicates > 1))
{
    AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
}

This removes the inner if and expresses the same condition via Where. No additional imports are necessary because LINQ extension methods like Where are already being used earlier in the file (req.PollingStations.Where(...)), implying the relevant using System.Linq; is present somewhere in the compilation unit. Only the loop region (lines 41–47) needs to be updated.

Suggested changeset 1
api/src/Feature.PollingStations/Create/Endpoint.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/src/Feature.PollingStations/Create/Endpoint.cs b/api/src/Feature.PollingStations/Create/Endpoint.cs
--- a/api/src/Feature.PollingStations/Create/Endpoint.cs
+++ b/api/src/Feature.PollingStations/Create/Endpoint.cs
@@ -38,12 +38,9 @@
         var groupedPollingStationIds = pollingStationIds.GroupBy(id => id, y => y,
             (id, duplicates) => new { id, numberOfDuplicates = duplicates.Count() });
 
-        foreach (var groupedPollingStationId in groupedPollingStationIds)
+        foreach (var groupedPollingStationId in groupedPollingStationIds.Where(g => g.numberOfDuplicates > 1))
         {
-            if (groupedPollingStationId.numberOfDuplicates > 1)
-            {
-                AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
-            }
+            AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
         }
 
         ThrowIfAnyErrors();
EOF
@@ -38,12 +38,9 @@
var groupedPollingStationIds = pollingStationIds.GroupBy(id => id, y => y,
(id, duplicates) => new { id, numberOfDuplicates = duplicates.Count() });

foreach (var groupedPollingStationId in groupedPollingStationIds)
foreach (var groupedPollingStationId in groupedPollingStationIds.Where(g => g.numberOfDuplicates > 1))
{
if (groupedPollingStationId.numberOfDuplicates > 1)
{
AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
}
AddError(new ValidationFailure(groupedPollingStationId.id.ToString(), "This id is duplicated"));
}

ThrowIfAnyErrors();
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant