Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func newScanCommand() *cobra.Command {
func newArticlesCommand() *cobra.Command {
var showAll bool
var blogName string
var category string

cmd := &cobra.Command{
Use: "articles",
Expand All @@ -205,7 +206,7 @@ func newArticlesCommand() *cobra.Command {
return err
}
defer db.Close()
articles, blogNames, err := controller.GetArticles(db, showAll, blogName)
articles, blogNames, err := controller.GetArticles(db, showAll, blogName, category)
if err != nil {
printError(err)
return markError(err)
Expand Down Expand Up @@ -233,6 +234,7 @@ func newArticlesCommand() *cobra.Command {

cmd.Flags().BoolVarP(&showAll, "all", "a", false, "Show all articles (including read)")
cmd.Flags().StringVarP(&blogName, "blog", "b", "", "Filter by blog name")
cmd.Flags().StringVarP(&category, "category", "c", "", "Filter by category")
return cmd
}

Expand Down Expand Up @@ -281,7 +283,7 @@ func newReadAllCommand() *cobra.Command {
}
defer db.Close()

articles, blogNames, err := controller.GetArticles(db, false, blogName)
articles, blogNames, err := controller.GetArticles(db, false, blogName, "")
if err != nil {
printError(err)
return markError(err)
Expand Down
16 changes: 7 additions & 9 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func AddBlog(db *storage.Database, name string, url string, feedURL string, scra
} else if existing != nil {
return model.Blog{}, BlogAlreadyExistsError{Field: "URL", Value: url}
}

blog := model.Blog{
Name: name,
URL: url,
Expand All @@ -65,7 +64,7 @@ func RemoveBlog(db *storage.Database, name string) error {
return err
}

func GetArticles(db *storage.Database, showAll bool, blogName string) ([]model.Article, map[int64]string, error) {
func GetArticles(db *storage.Database, showAll bool, blogName string, category string) ([]model.Article, map[int64]string, error) {
var blogID *int64
if blogName != "" {
blog, err := db.GetBlogByName(blogName)
Expand All @@ -77,8 +76,11 @@ func GetArticles(db *storage.Database, showAll bool, blogName string) ([]model.A
}
blogID = &blog.ID
}

articles, err := db.ListArticles(!showAll, blogID)
var categoryPtr *string
if category != "" {
categoryPtr = &category
}
articles, err := db.ListArticles(!showAll, blogID, categoryPtr)
if err != nil {
return nil, nil, err
}
Expand All @@ -90,7 +92,6 @@ func GetArticles(db *storage.Database, showAll bool, blogName string) ([]model.A
for _, blog := range blogs {
blogNames[blog.ID] = blog.Name
}

return articles, blogNames, nil
}

Expand Down Expand Up @@ -123,19 +124,16 @@ func MarkAllArticlesRead(db *storage.Database, blogName string) ([]model.Article
}
blogID = &blog.ID
}

articles, err := db.ListArticles(true, blogID)
articles, err := db.ListArticles(true, blogID, nil)
if err != nil {
return nil, err
}

for _, article := range articles {
_, err := db.MarkArticleRead(article.ID)
if err != nil {
return nil, err
}
}

return articles, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestGetArticlesFilters(t *testing.T) {
t.Fatalf("add article: %v", err)
}

articles, blogNames, err := GetArticles(db, false, "")
articles, blogNames, err := GetArticles(db, false, "", "")
if err != nil {
t.Fatalf("get articles: %v", err)
}
Expand All @@ -84,7 +84,7 @@ func TestGetArticlesFilters(t *testing.T) {
t.Fatalf("expected blog name")
}

if _, _, err := GetArticles(db, false, "Missing"); err == nil {
if _, _, err := GetArticles(db, false, "Missing", ""); err == nil {
t.Fatalf("expected blog not found error")
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ type Article struct {
PublishedDate *time.Time
DiscoveredDate *time.Time
IsRead bool
Categories []string
}
2 changes: 2 additions & 0 deletions internal/rss/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type FeedArticle struct {
Title string
URL string
PublishedDate *time.Time
Categories []string
}

type FeedParseError struct {
Expand Down Expand Up @@ -54,6 +55,7 @@ func ParseFeed(feedURL string, timeout time.Duration) ([]FeedArticle, error) {
Title: title,
URL: link,
PublishedDate: pickPublishedDate(item),
Categories: item.Categories,
})
}

Expand Down
1 change: 1 addition & 0 deletions internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func convertFeedArticles(blogID int64, articles []rss.FeedArticle) []model.Artic
URL: article.URL,
PublishedDate: article.PublishedDate,
IsRead: false,
Categories: article.Categories,
})
}
return result
Expand Down
2 changes: 1 addition & 1 deletion internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestScanBlogRSS(t *testing.T) {
t.Fatalf("expected rss source, got %s", result.Source)
}

articles, err := db.ListArticles(false, nil)
articles, err := db.ListArticles(false, nil, nil)
if err != nil {
t.Fatalf("list articles: %v", err)
}
Expand Down
Loading