summaryrefslogtreecommitdiffstats
path: root/pkg/entries/entries.go
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-09-18 21:00:28 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-09-18 21:00:28 +0100
commit9e779891fa91f44a9734b79ccb4f6aef48a0de3f (patch)
tree7b60a2129966461ed56532768c847595fd371377 /pkg/entries/entries.go
parent39a926cd521806aedc298ddd671d1a118794fcec (diff)
Add filters on html page
Diffstat (limited to 'pkg/entries/entries.go')
-rw-r--r--pkg/entries/entries.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/pkg/entries/entries.go b/pkg/entries/entries.go
index 92f28d9..466f340 100644
--- a/pkg/entries/entries.go
+++ b/pkg/entries/entries.go
@@ -13,7 +13,8 @@ type Service interface {
CreateEntry(title, kind, url, description string) (*sqlc.Entry, error)
UpdateEntryKind(id int64, kind string) (*sqlc.Entry, error)
DeleteEntry(id int64) error
- GetEntries() ([]sqlc.GetEntriesRow, error)
+ GetEntries() ([]EntryRow, error)
+ GetEntriesByKind(kind string) ([]EntryRow, error)
GetEntryURLs() ([]string, error)
GetEntryByUrl(url string) (*sqlc.GetEntryByUrlRow, error)
}
@@ -73,12 +74,33 @@ func (s *service) DeleteEntry(id int64) error {
return err
}
-func (s *service) GetEntries() ([]sqlc.GetEntriesRow, error) {
+func (s *service) GetEntries() ([]EntryRow, error) {
queries := sqlc.New(s.db)
- entries, err := queries.GetEntries(context.Background())
+ response, err := queries.GetEntries(context.Background())
+ entries := make([]EntryRow, len(response))
if err != nil {
- return make([]sqlc.GetEntriesRow, 0), fmt.Errorf("could not get entries: %w", err)
+ return entries, fmt.Errorf("could not get entries: %w", err)
+ }
+
+ for i := range response {
+ entries[i].ScanGetEntriesRow(response[i])
+ }
+
+ return entries, nil
+}
+
+func (s *service) GetEntriesByKind(kind string) ([]EntryRow, error) {
+ queries := sqlc.New(s.db)
+
+ response, err := queries.GetEntriesByKind(context.Background(), kind)
+ entries := make([]EntryRow, len(response))
+ if err != nil {
+ return entries, fmt.Errorf("could not get entries: %w", err)
+ }
+
+ for i := range response {
+ entries[i].ScanGetEntriesByKindRow(response[i])
}
return entries, nil