diff options
Diffstat (limited to 'pkg/entries/entries.go')
| -rw-r--r-- | pkg/entries/entries.go | 30 |
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 |
