forked from jason/cpolis
Allow articles to be independent of an issue and allow a title for an issue
This commit is contained in:
@ -9,18 +9,20 @@ import (
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
Title string
|
||||
Created time.Time
|
||||
Description string
|
||||
Link string
|
||||
EncURL string
|
||||
EncLength int
|
||||
EncType string
|
||||
Published bool
|
||||
Rejected bool
|
||||
ID int64
|
||||
AuthorID int64
|
||||
IssueID int64
|
||||
Title string
|
||||
Created time.Time
|
||||
Description string
|
||||
Link string
|
||||
EncURL string
|
||||
EncLength int
|
||||
EncType string
|
||||
Published bool
|
||||
Rejected bool
|
||||
ID int64
|
||||
AuthorID int64
|
||||
IssueID int64
|
||||
IsInIssue bool
|
||||
AutoGenerated bool
|
||||
}
|
||||
|
||||
func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
@ -29,8 +31,8 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
selectQuery := "SELECT id FROM issues WHERE published = false"
|
||||
insertQuery := `
|
||||
INSERT INTO articles
|
||||
(title, description, link, enc_url, enc_length, enc_type, published, rejected, author_id, issue_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
(title, description, link, enc_url, enc_length, enc_type, published, rejected, author_id, issue_id, is_in_issue, auto_generated)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
for i := 0; i < TxMaxRetries; i++ {
|
||||
@ -47,8 +49,10 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
return 0, fmt.Errorf("error getting issue ID when adding article to DB: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println(a)
|
||||
result, err := tx.Exec(insertQuery, a.Title, a.Description, a.Link,
|
||||
a.EncURL, a.EncLength, a.EncType, a.Published, a.Rejected, a.AuthorID, id)
|
||||
a.EncURL, a.EncLength, a.EncType, a.Published, a.Rejected, a.AuthorID, id,
|
||||
a.IsInIssue, a.AutoGenerated)
|
||||
if err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||
@ -82,7 +86,7 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
|
||||
func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
query := `
|
||||
SELECT title, created, description, link, enc_url, enc_length, enc_type, published, author_id
|
||||
SELECT title, created, description, link, enc_url, enc_length, enc_type, published, author_id, issue_id, is_in_issue, auto_generated
|
||||
FROM articles
|
||||
WHERE id = ?
|
||||
`
|
||||
@ -94,7 +98,8 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
|
||||
if err := row.Scan(&article.Title, &created, &article.Description,
|
||||
&article.Link, &article.EncURL, &article.EncLength, &article.EncType,
|
||||
&article.Published, &article.AuthorID); err != nil {
|
||||
&article.Published, &article.AuthorID, &article.IssueID,
|
||||
&article.IsInIssue, &article.AutoGenerated); err != nil {
|
||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||
}
|
||||
|
||||
@ -109,7 +114,7 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
|
||||
func (db *DB) GetCertainArticles(published, rejected bool) ([]*Article, error) {
|
||||
query := `
|
||||
SELECT id, title, created, description, link, enc_url, enc_length, enc_type, author_id, issue_id
|
||||
SELECT id, title, created, description, link, enc_url, enc_length, enc_type, author_id, issue_id, is_in_issue, auto_generated
|
||||
FROM articles
|
||||
WHERE published = ?
|
||||
AND rejected = ?
|
||||
@ -126,7 +131,8 @@ func (db *DB) GetCertainArticles(published, rejected bool) ([]*Article, error) {
|
||||
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created,
|
||||
&article.Description, &article.Link, &article.EncURL, &article.EncLength,
|
||||
&article.EncType, &article.AuthorID, &article.IssueID); err != nil {
|
||||
&article.EncType, &article.AuthorID, &article.IssueID,
|
||||
&article.IsInIssue, &article.AutoGenerated); err != nil {
|
||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||
}
|
||||
|
||||
@ -147,9 +153,9 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
||||
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||
issueQuery := "SELECT id FROM issues WHERE published = false"
|
||||
articlesQuery := `
|
||||
SELECT id, title, created, description, link, enc_url, enc_length, enc_type, author_id
|
||||
SELECT id, title, created, description, link, enc_url, enc_length, enc_type, author_id, auto_generated
|
||||
FROM articles
|
||||
WHERE issue_id = ? AND published = true
|
||||
WHERE issue_id = ? AND published = true AND is_in_issue = true
|
||||
`
|
||||
|
||||
for i := 0; i < TxMaxRetries; i++ {
|
||||
@ -182,7 +188,7 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
||||
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created,
|
||||
&article.Description, &article.Link, &article.EncURL, &article.EncLength,
|
||||
&article.EncType, &article.AuthorID); err != nil {
|
||||
&article.EncType, &article.AuthorID, &article.AutoGenerated); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||
}
|
||||
|
@ -31,7 +31,10 @@ func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
for _, tag := range tags {
|
||||
tagNames = append(tagNames, tag.Name)
|
||||
}
|
||||
tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID))
|
||||
|
||||
if article.IsInIssue {
|
||||
tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID))
|
||||
}
|
||||
|
||||
user, err := db.GetUser(article.AuthorID)
|
||||
if err != nil {
|
||||
@ -57,9 +60,8 @@ func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
PubDate: article.Created.Format(time.RFC1123Z),
|
||||
Title: articleTitle,
|
||||
}
|
||||
fmt.Println(article.Link, ": ", len(article.Link))
|
||||
|
||||
if article.Title == "Autogenerated cpolis Issue Article" {
|
||||
if article.AutoGenerated {
|
||||
item.Enclosure = &rss.Enclosure{
|
||||
Url: article.EncURL,
|
||||
Lenght: article.EncLength,
|
||||
|
Reference in New Issue
Block a user