Skip to content

Commit

Permalink
Updated FrontpageController
Browse files Browse the repository at this point in the history
Changed the logic for getFilteredCharities to need to include ALL categories/filters to show a category.
  • Loading branch information
roaraf committed Apr 18, 2026
1 parent 421c648 commit ca8001e
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -162,7 +163,10 @@ public void handleFrontSearch(ActionEvent event) {
* This method is used to filter the charities based on the selected filters.
*
* <p>The filters are whether the charity was pre-verified, or if it falls under one (or more) of
* the given categories.
* the given categories.</p>
*
* <p>The check checks whether the given charity has ALL filters. If one does not apply,
* the charity is rejected.</p>
*
* @return a list of filtered charities.
*/
Expand All @@ -178,21 +182,18 @@ private List<Charity> getFilteredCharities() {

if (!selectedCategories.isEmpty()) {

boolean hasMatch = false;

for (String cat : charity.getCategory()) {
if (cat == null) continue;
boolean hasAll =
charity.getCategory().stream()
.filter(Objects::nonNull)
.map(c -> c.toLowerCase().trim())
.collect(java.util.stream.Collectors.toSet())
.containsAll(selectedCategories);

if (selectedCategories.contains(cat.toLowerCase().trim())) {
hasMatch = true;
break;
}
}

if (!hasMatch) {
if (!hasAll) {
continue;
}
}

filtered.add(charity);
}

Expand Down

0 comments on commit ca8001e

Please sign in to comment.