-
Notifications
You must be signed in to change notification settings - Fork 26
Add gps coordinates to polling stations #1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gps coordinates to polling stations #1048
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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
implicitly filters its target sequence
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 hour 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.
-
Copy modified line R41 -
Copy modified line R43
| @@ -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(); |
No description provided.