removed wrong stuff

This commit is contained in:
Hazel Noack
2025-07-10 13:05:38 +02:00
parent 46cc8b7989
commit 2e1d7d5564
7 changed files with 21 additions and 132 deletions

View File

@@ -2,8 +2,7 @@ package diyhrt
import (
"encoding/json"
"fmt"
"io"
"errors"
"net/http"
"os"
"time"
@@ -14,7 +13,7 @@ const endpoint = "https://diyhrt.market/api/listings"
func GetListings() ([]Listing, error) {
apiKey := os.Getenv("API_KEY")
if apiKey == "" {
return nil, fmt.Errorf("API_KEY environment variable not set")
return nil, errors.New("API_KEY environment variable not set")
}
// Create HTTP client
@@ -23,26 +22,25 @@ func GetListings() ([]Listing, error) {
// Create request
req, err := http.NewRequest("GET", endpoint+"?api_token="+apiKey, nil)
if err != nil {
return nil, fmt.Errorf("creating request failed: %w", err)
return nil, err
}
// Send request
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
return nil, err
}
defer resp.Body.Close()
// Check status code
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("unexpected status code %d: %s", resp.StatusCode, string(body))
return nil, errors.New("unexpected status code")
}
// Decode response
var listings []Listing
if err := json.NewDecoder(resp.Body).Decode(&listings); err != nil {
return nil, fmt.Errorf("decoding failed: %w", err)
return nil, err
}
return listings, nil

View File

@@ -1,6 +1,9 @@
package diyhrt
import "slices"
import (
"fmt"
"slices"
)
type StoreFilter struct{
Limit int
@@ -34,5 +37,6 @@ func (f StoreFilter) Filter (stores []Store) []Store {
result = append(result, s)
}
fmt.Println(len(result))
return result
}

View File

@@ -1,8 +1,6 @@
package rendering
import (
"fmt"
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
)
@@ -15,6 +13,8 @@ type RenderingConfig struct {
SearchFormAction string
SearchInputName string
StoreFilter diyhrt.StoreFilter
Listings []diyhrt.Listing
Stores []diyhrt.Store
}
@@ -36,6 +36,10 @@ func DefaultRenderingConfig() RenderingConfig {
SearchPlaceholder: "Search on DuckDuckGo",
SearchFormAction: "https://duckduckgo.com/",
SearchInputName: "q",
StoreFilter: diyhrt.StoreFilter{
Limit: 5,
},
}
}
@@ -44,7 +48,6 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
stores := make([]diyhrt.Store, 0)
for _, listing := range listings {
fmt.Println(listing)
if _, ok := existingStores[listing.Store.Id]; ok {
continue
}
@@ -53,5 +56,5 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
}
rc.Listings = listings
rc.Stores = stores
rc.Stores = rc.StoreFilter.Filter(stores)
}