mirror of
https://github.com/miniflux/v2.git
synced 2025-07-22 17:18:37 +00:00
Display list of feeds per category
This commit is contained in:
parent
15fe9c20df
commit
fad9ad2be4
22 changed files with 345 additions and 141 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue