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