66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package utils
|
|
|
|
type FilterJsonData struct {
|
|
Order int `json:"order"`
|
|
En string `json:"en"`
|
|
Ar string `json:"ar"`
|
|
}
|
|
|
|
type FilterGroup struct {
|
|
FilterKey string `json:"filter_key"`
|
|
FilterData []interface{} `json:"filter_data"`
|
|
FilterTextAndOrder FilterJsonData `json:"filter_text_and_order"`
|
|
}
|
|
|
|
// RemoveExcludedFilters removes specified filter_data values from filters.
|
|
func RemoveExcludedFilters(filters []FilterGroup, exclusions []FilterGroup) []FilterGroup {
|
|
// Create a map for quick lookup of exclusion filter data
|
|
exclusionMap := make(map[string]map[interface{}]bool)
|
|
|
|
// Populate the exclusion map
|
|
for _, excl := range exclusions {
|
|
if _, exists := exclusionMap[excl.FilterKey]; !exists {
|
|
exclusionMap[excl.FilterKey] = make(map[interface{}]bool)
|
|
}
|
|
for _, value := range excl.FilterData {
|
|
exclusionMap[excl.FilterKey][value] = true
|
|
}
|
|
}
|
|
|
|
// Debug: Print exclusionMap to verify exclusions
|
|
// log.Println("Exclusion Map: ", exclusionMap)
|
|
|
|
// Process the filters and remove excluded values
|
|
var filteredFilters []FilterGroup
|
|
|
|
for _, filter := range filters {
|
|
if excludedValues, found := exclusionMap[filter.FilterKey]; found {
|
|
// Debug: Print current filter data and exclusions
|
|
// log.Printf("Checking filter: %s with data: %v", filter.FilterKey, filter.FilterData)
|
|
|
|
// Remove excluded values
|
|
var newFilterData []interface{}
|
|
for _, value := range filter.FilterData {
|
|
// Debug: Check if value is excluded
|
|
if _, exists := excludedValues[value]; exists {
|
|
// log.Printf("Excluding value: %v", value) // Debug log for excluded value
|
|
} else {
|
|
newFilterData = append(newFilterData, value)
|
|
}
|
|
}
|
|
if len(newFilterData) > 0 {
|
|
filter.FilterData = newFilterData
|
|
filteredFilters = append(filteredFilters, filter)
|
|
}
|
|
} else {
|
|
// No exclusions, add filter as is
|
|
filteredFilters = append(filteredFilters, filter)
|
|
}
|
|
}
|
|
|
|
// Debug: Print final filtered result
|
|
// log.Println("Filtered Filters: ", filteredFilters)
|
|
|
|
return filteredFilters
|
|
}
|