Compare commits
No commits in common. "27adda431f765bfb7d1f5bfb588267e92ce32955" and "a4ec4966d247b5c2a14bb6ce35bb774984d6d86a" have entirely different histories.
27adda431f
...
a4ec4966d2
@ -1,6 +1,7 @@
|
||||
package diyhrt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
@ -9,39 +10,33 @@ type StoreFilter struct{
|
||||
|
||||
IncludeIds []int
|
||||
ExcludeIds []int
|
||||
|
||||
ShipsTo []string
|
||||
}
|
||||
|
||||
|
||||
func (f StoreFilter) Filter (stores []Store) []Store {
|
||||
result := make([]Store, 0)
|
||||
|
||||
if len(f.IncludeIds) > 0 {
|
||||
for _, s := range stores {
|
||||
if f.Limit > 0 && len(result) >= f.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
if slices.Contains(f.IncludeIds, s.Id) {
|
||||
result = append(result, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for _, s := range stores {
|
||||
if f.Limit > 0 && len(result) >= f.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if slices.Contains(f.ExcludeIds, s.Id) || slices.Contains(f.IncludeIds, s.Id) {
|
||||
if len(f.IncludeIds) > 0 {
|
||||
if slices.Contains(f.IncludeIds, s.Id) {
|
||||
result = append(result, s)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if slices.Contains(f.ExcludeIds, s.Id) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
result = append(result, s)
|
||||
}
|
||||
|
||||
fmt.Println(len(result))
|
||||
return result
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package rendering
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||
)
|
||||
|
||||
@ -42,18 +39,22 @@ func DefaultRenderingConfig() RenderingConfig {
|
||||
|
||||
StoreFilter: diyhrt.StoreFilter{
|
||||
Limit: 4,
|
||||
IncludeIds: []int{7},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
existingStores := make(map[int]diyhrt.Store)
|
||||
existingStores := make(map[int]struct{})
|
||||
stores := make([]diyhrt.Store, 0)
|
||||
|
||||
for _, listing := range listings {
|
||||
existingStores[listing.Store.Id] = listing.Store
|
||||
if _, ok := existingStores[listing.Store.Id]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
stores = append(stores, listing.Store)
|
||||
}
|
||||
|
||||
rc.Listings = listings
|
||||
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
|
||||
rc.Stores = rc.StoreFilter.Filter(stores)
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
Loading…
x
Reference in New Issue
Block a user