From 9868f900e972edd6d4811b4a93b1955e4222e9b1 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 22 Dec 2017 11:33:01 -0800 Subject: Add bookmarks --- storage/entry.go | 15 ++++++++++++++- storage/entry_query_builder.go | 16 +++++++++++++++- storage/migration.go | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) (limited to 'storage') diff --git a/storage/entry.go b/storage/entry.go index 6d67397..8a12f5e 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -179,11 +179,24 @@ func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string return nil } +// ToggleBookmark toggles entry bookmark value. +func (s *Storage) ToggleBookmark(userID int64, entryID int64) error { + defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:ToggleBookmark] userID=%d, entryID=%d", userID, entryID)) + + query := `UPDATE entries SET starred = NOT starred WHERE user_id=$1 AND id=$2` + _, err := s.db.Exec(query, userID, entryID) + if err != nil { + return fmt.Errorf("unable to update toggle bookmark: %v", err) + } + + return nil +} + // FlushHistory set all entries with the status "read" to "removed". func (s *Storage) FlushHistory(userID int64) error { defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FlushHistory] userID=%d", userID)) - query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3` + query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3 AND starred='f'` _, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead) if err != nil { return fmt.Errorf("unable to flush history: %v", err) diff --git a/storage/entry_query_builder.go b/storage/entry_query_builder.go index 57e708c..040c717 100644 --- a/storage/entry_query_builder.go +++ b/storage/entry_query_builder.go @@ -32,6 +32,13 @@ type EntryQueryBuilder struct { greaterThanEntryID int64 entryIDs []int64 before *time.Time + starred bool +} + +// WithStarred adds starred filter. +func (e *EntryQueryBuilder) WithStarred() *EntryQueryBuilder { + e.starred = true + return e } // Before add condition base on the entry date. @@ -150,7 +157,8 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { query := ` SELECT - e.id, e.user_id, e.feed_id, e.hash, e.published_at at time zone '%s', e.title, e.url, e.author, e.content, e.status, + e.id, e.user_id, e.feed_id, e.hash, e.published_at at time zone '%s', e.title, + e.url, e.author, e.content, e.status, e.starred, f.title as feed_title, f.feed_url, f.site_url, f.checked_at, f.category_id, c.title as category_title, f.scraper_rules, f.rewrite_rules, f.crawler, fi.icon_id @@ -191,6 +199,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { &entry.Author, &entry.Content, &entry.Status, + &entry.Starred, &entry.Feed.Title, &entry.Feed.FeedURL, &entry.Feed.SiteURL, @@ -303,6 +312,10 @@ func (e *EntryQueryBuilder) buildCondition() ([]interface{}, string) { args = append(args, e.before) } + if e.starred { + conditions = append(conditions, "e.starred is true") + } + return args, strings.Join(conditions, " AND ") } @@ -334,5 +347,6 @@ func NewEntryQueryBuilder(store *Storage, userID int64, timezone string) *EntryQ store: store, userID: userID, timezone: timezone, + starred: false, } } diff --git a/storage/migration.go b/storage/migration.go index 0408330..c10da45 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -12,7 +12,7 @@ import ( "github.com/miniflux/miniflux/sql" ) -const schemaVersion = 11 +const schemaVersion = 12 // Migrate run database migrations. func (s *Storage) Migrate() { -- cgit v1.2.3