From 08d2446329e307c4e870ba729ef3e287e69da8ca Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 10 Jul 2025 14:55:10 +0200 Subject: [PATCH] added from stores --- internal/diyhrt/filter.go | 46 ++++++++++++++++++++++++++++++++++++ internal/rendering/config.go | 7 +++++- tmp/build-errors.log | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/internal/diyhrt/filter.go b/internal/diyhrt/filter.go index bba4f3f..efe69f3 100644 --- a/internal/diyhrt/filter.go +++ b/internal/diyhrt/filter.go @@ -45,3 +45,49 @@ func (f StoreFilter) Filter (stores []Store) []Store { return result } + +type ListingFilter struct{ + Limit int + + IncludeIds []int + ExcludeIds []int + + FromStores []int +} + + +func (f ListingFilter) Filter (listings []Listing) []Listing { + result := make([]Listing, 0) + + if len(f.IncludeIds) > 0 { + for _, l := range listings { + if f.Limit > 0 && len(result) >= f.Limit { + break + } + + if slices.Contains(f.IncludeIds, l.Id) { + result = append(result, l) + } + } + } + + + for _, l := range listings { + if f.Limit > 0 && len(result) >= f.Limit { + break + } + + + if slices.Contains(f.ExcludeIds, l.Id) || slices.Contains(f.IncludeIds, l.Id) { + continue + } + + if len(f.FromStores) > 0 && !slices.Contains(f.FromStores, l.Store.Id) { + continue + } + + result = append(result, l) + } + + return result +} diff --git a/internal/rendering/config.go b/internal/rendering/config.go index 0423191..67583d4 100644 --- a/internal/rendering/config.go +++ b/internal/rendering/config.go @@ -17,6 +17,7 @@ type RenderingConfig struct { SearchInputName string StoreFilter diyhrt.StoreFilter + ListingFilter diyhrt.ListingFilter Listings []diyhrt.Listing Stores []diyhrt.Store @@ -44,6 +45,10 @@ func DefaultRenderingConfig() RenderingConfig { Limit: 0, IncludeIds: []int{7}, }, + + ListingFilter: diyhrt.ListingFilter{ + FromStores: []int{7}, + }, } } @@ -54,6 +59,6 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) { existingStores[listing.Store.Id] = listing.Store } - rc.Listings = listings + rc.Listings = rc.ListingFilter.Filter(listings) rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores))) } diff --git a/tmp/build-errors.log b/tmp/build-errors.log index f208b22..0f17b9c 100644 --- a/tmp/build-errors.log +++ b/tmp/build-errors.log @@ -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 \ No newline at end of file +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 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file