feat: implements today command
This commit is contained in:
parent
09f4b2a838
commit
a77d4f9604
5 changed files with 101 additions and 14 deletions
30
internal/article.go
Normal file
30
internal/article.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"freed/internal/database"
|
||||
)
|
||||
|
||||
func GetArticleUrlForToday() (string, error) {
|
||||
count, err := database.CountArticlesReadToday()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
return "", fmt.Errorf("Already reached maximum number of articles for the day. Come back tomorrow!")
|
||||
}
|
||||
|
||||
article, err := database.FindOneUnreadArticle()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := article.MarkAsRead(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return article.Url, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue