diff options
author | Frédéric Guillot <fred@miniflux.net> | 2019-11-17 19:44:12 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2019-11-17 20:10:44 -0800 |
commit | fad9ad2be4fc800f8710e2a498cc8f536af8827c (patch) | |
tree | 8bc4f134b63f100442850bd9eb443f03fffcf7e6 /storage | |
parent | 15fe9c20df7eaab4c1e10461f1a9965eeaf85f0f (diff) |
Display list of feeds per category
Diffstat (limited to 'storage')
-rw-r--r-- | storage/feed.go | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/storage/feed.go b/storage/feed.go index f6ad021..6db3488 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -139,7 +139,6 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) { // FeedsWithCounters returns all feeds of the given user with counters of read and unread entries. func (s *Storage) FeedsWithCounters(userID int64) (model.Feeds, error) { - feeds := make(model.Feeds, 0) query := ` SELECT f.id, @@ -166,7 +165,43 @@ func (s *Storage) FeedsWithCounters(userID int64) (model.Feeds, error) { f.user_id=$1 ORDER BY f.parsing_error_count DESC, unread_count DESC, lower(f.title) ASC ` - rows, err := s.db.Query(query, userID) + return s.fetchFeedsWithCounters(query, userID) +} + +// FeedsByCategoryWithCounters returns all feeds of the given user/category with counters of read and unread entries. +func (s *Storage) FeedsByCategoryWithCounters(userID, categoryID int64) (model.Feeds, error) { + query := ` + SELECT + f.id, + f.feed_url, + f.site_url, + f.title, + f.etag_header, + f.last_modified_header, + f.user_id, + f.checked_at at time zone u.timezone, + f.parsing_error_count, f.parsing_error_msg, + f.scraper_rules, f.rewrite_rules, f.crawler, f.user_agent, + f.username, f.password, f.disabled, + f.category_id, c.title as category_title, + fi.icon_id, + u.timezone, + (SELECT count(*) FROM entries WHERE entries.feed_id=f.id AND status='unread') as unread_count, + (SELECT count(*) FROM entries WHERE entries.feed_id=f.id AND status='read') as read_count + FROM feeds f + LEFT JOIN categories c ON c.id=f.category_id + LEFT JOIN feed_icons fi ON fi.feed_id=f.id + LEFT JOIN users u ON u.id=f.user_id + WHERE + f.user_id=$1 AND f.category_id=$2 + ORDER BY f.parsing_error_count DESC, unread_count DESC, lower(f.title) ASC + ` + return s.fetchFeedsWithCounters(query, userID, categoryID) +} + +func (s *Storage) fetchFeedsWithCounters(query string, args ...interface{}) (model.Feeds, error) { + feeds := make(model.Feeds, 0) + rows, err := s.db.Query(query, args...) if err != nil { return nil, fmt.Errorf(`store: unable to fetch feeds: %v`, err) } @@ -176,7 +211,7 @@ func (s *Storage) FeedsWithCounters(userID int64) (model.Feeds, error) { var feed model.Feed var iconID interface{} var tz string - feed.Category = &model.Category{UserID: userID} + feed.Category = &model.Category{} err := rows.Scan( &feed.ID, @@ -213,6 +248,7 @@ func (s *Storage) FeedsWithCounters(userID int64) (model.Feeds, error) { } feed.CheckedAt = timezone.Convert(tz, feed.CheckedAt) + feed.Category.UserID = feed.UserID feeds = append(feeds, &feed) } |