feat: complete Task 2 - update filtering core logic for live/remix filtering
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
type FilterOptions struct {
|
||||
IgnoreSingles bool
|
||||
IgnoreCompilations bool
|
||||
IgnoreLive bool
|
||||
IgnoreRemix bool
|
||||
}
|
||||
|
||||
// hasSliceType reports whether the slice contains any of the wanted values.
|
||||
@@ -24,8 +26,11 @@ func hasSliceType(types []string, wanted ...string) bool {
|
||||
|
||||
// ApplyTypeToggles filters releases based on the IgnoreSingles and IgnoreCompilations flags.
|
||||
// Implements canonical filtering logic:
|
||||
// IgnoreSingles filters: Type == "Single" OR Type == "EP" OR SecondaryTypes contains "Single" OR "EP"
|
||||
// IgnoreCompilations filters: Type == "Compilation" OR SecondaryTypes contains "Compilation"
|
||||
//
|
||||
// IgnoreSingles filters: Type == "Single" OR Type == "EP" OR SecondaryTypes contains "Single" OR "EP"
|
||||
// IgnoreCompilations filters: Type == "Compilation" OR SecondaryTypes contains "Compilation"
|
||||
// IgnoreLive filters: Type == "Live" OR SecondaryTypes contains "Live"
|
||||
// IgnoreRemix filters: Type == "Remix" OR SecondaryTypes contains "Remix"
|
||||
func ApplyTypeToggles(releases []database.ExternalRelease, opts FilterOptions) []database.ExternalRelease {
|
||||
var result []database.ExternalRelease
|
||||
for _, release := range releases {
|
||||
@@ -43,6 +48,20 @@ func ApplyTypeToggles(releases []database.ExternalRelease, opts FilterOptions) [
|
||||
}
|
||||
}
|
||||
|
||||
// Apply IgnoreLive filtering: filter out if Type is Live OR SecondaryTypes contains Live
|
||||
if opts.IgnoreLive {
|
||||
if release.Type == "Live" || hasSliceType(release.SecondaryTypes, "Live") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Apply IgnoreRemix filtering: filter out if Type is Remix OR SecondaryTypes contains Remix
|
||||
if opts.IgnoreRemix {
|
||||
if release.Type == "Remix" || hasSliceType(release.SecondaryTypes, "Remix") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, release)
|
||||
}
|
||||
return result
|
||||
@@ -67,7 +86,21 @@ func ApplyTypeTogglesToReleaseGroups(groups []ReleaseGroup, opts FilterOptions)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply IgnoreLive filtering: filter out if Type is Live OR SecondaryTypes contains Live
|
||||
if opts.IgnoreLive {
|
||||
if rg.Type == "Live" || hasSliceType(rg.SecondaryTypes, "Live") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Apply IgnoreRemix filtering: filter out if Type is Remix OR SecondaryTypes contains Remix
|
||||
if opts.IgnoreRemix {
|
||||
if rg.Type == "Remix" || hasSliceType(rg.SecondaryTypes, "Remix") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, rg)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user