diff options
author | Adam Mathes <adam@trenchant.org> | 2018-04-22 16:31:19 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-04-22 16:31:19 -0700 |
commit | b376d197b51f2e67c314e23b8ac484dc2ae8f4a5 (patch) | |
tree | 9699832c43969531d6a3576b31f3e6d002e5ede4 /models/item | |
parent | cd1509967d7dafbf2d1a051206e368bd3aa5e179 (diff) | |
download | neko-b376d197b51f2e67c314e23b8ac484dc2ae8f4a5.tar.gz neko-b376d197b51f2e67c314e23b8ac484dc2ae8f4a5.tar.bz2 neko-b376d197b51f2e67c314e23b8ac484dc2ae8f4a5.zip |
wip single category on feed
Diffstat (limited to 'models/item')
-rw-r--r-- | models/item/item.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/models/item/item.go b/models/item/item.go index c5ffff9..b3dc5eb 100644 --- a/models/item/item.go +++ b/models/item/item.go @@ -19,9 +19,10 @@ type Item struct { Description string `json:"description"` PublishDate string `json:"publish_date"` - FeedId int64 - FeedTitle string `json:"feed_title"` - FeedUrl string `json:"feed_url"` + FeedId int64 + FeedTitle string `json:"feed_title"` + FeedUrl string `json:"feed_url"` + FeedCategory string `json:"feed_category"` ReadState bool `json:"read"` Starred bool `json:"starred"` @@ -112,16 +113,16 @@ func (i *Item) GetFullContent() { } } -func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([]*Item, error) { +func Filter(max_id int64, feed_id int64, category string, unread_only bool, starred_only bool) ([]*Item, error) { var args []interface{} query := `SELECT item.id, item.title, item.url, item.description, item.read_state, item.starred, item.publish_date, item.full_content, item.header_image, - feed.url, feed.title - FROM item,feed - WHERE item.feed_id=feed.id ` + feed.url, feed.title, feed.category + FROM item,feed + WHERE item.feed_id=feed.id ` if max_id != 0 { query = query + "AND item.id < ? " @@ -133,6 +134,11 @@ func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([ args = append(args, feed_id) } + if category != "" { + query = query + " AND feed.category=? " + args = append(args, category) + } + if unread_only { query = query + " AND item.read_state=0 " } @@ -157,7 +163,7 @@ func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([ items := make([]*Item, 0) for rows.Next() { i := new(Item) - err := rows.Scan(&i.Id, &i.Title, &i.Url, &i.Description, &i.ReadState, &i.Starred, &i.PublishDate, &i.FullContent, &i.HeaderImage, &i.FeedUrl, &i.FeedTitle) + err := rows.Scan(&i.Id, &i.Title, &i.Url, &i.Description, &i.ReadState, &i.Starred, &i.PublishDate, &i.FullContent, &i.HeaderImage, &i.FeedUrl, &i.FeedTitle, &i.FeedCategory) if err != nil { log.Println(err) return nil, err |