From ca8001ed0962c5f983fd62b5a11968f5ef36f40e Mon Sep 17 00:00:00 2001 From: Roar Date: Sat, 18 Apr 2026 15:36:18 +0200 Subject: [PATCH] Updated FrontpageController Changed the logic for getFilteredCharities to need to include ALL categories/filters to show a category. --- .../team6/controller/FrontpageController.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index 6ac9ca8..1fd15cd 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -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; @@ -162,7 +163,10 @@ public void handleFrontSearch(ActionEvent event) { * This method is used to filter the charities based on the selected filters. * *

The filters are whether the charity was pre-verified, or if it falls under one (or more) of - * the given categories. + * the given categories.

+ * + *

The check checks whether the given charity has ALL filters. If one does not apply, + * the charity is rejected.

* * @return a list of filtered charities. */ @@ -178,21 +182,18 @@ private List 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); }