summaryrefslogtreecommitdiffstats
path: root/pkg/entries
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/entries')
-rw-r--r--pkg/entries/entries.go30
-rw-r--r--pkg/entries/model.go30
2 files changed, 56 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
diff --git a/pkg/entries/model.go b/pkg/entries/model.go
new file mode 100644
index 0000000..9ddcd20
--- /dev/null
+++ b/pkg/entries/model.go
@@ -0,0 +1,30 @@
+package entries
+
+import "git.leonardobishop.net/stash/pkg/database/sqlc"
+
+type EntryRow struct {
+ Title string `json:"title"`
+ Url string `json:"url"`
+ Description string `json:"description"`
+ Timestamp string `json:"timestamp"`
+ KindName string `json:"kind_name"`
+ KindEmoji string `json:"kind_emoji"`
+}
+
+func (dst *EntryRow) ScanGetEntriesByKindRow(src sqlc.GetEntriesByKindRow) {
+ dst.Title = src.Title
+ dst.Url = src.Url
+ dst.Description = src.Description
+ dst.Timestamp = src.Timestamp
+ dst.KindName = src.KindName
+ dst.KindEmoji = src.KindEmoji
+}
+
+func (dst *EntryRow) ScanGetEntriesRow(src sqlc.GetEntriesRow) {
+ dst.Title = src.Title
+ dst.Url = src.Url
+ dst.Description = src.Description
+ dst.Timestamp = src.Timestamp
+ dst.KindName = src.KindName
+ dst.KindEmoji = src.KindEmoji
+}