diff options
-rw-r--r-- | db/articles.rkt | 23 | ||||
-rw-r--r-- | entities/article.rkt | 3 | ||||
-rw-r--r-- | readers/article.rkt | 5 |
3 files changed, 20 insertions, 11 deletions
diff --git a/db/articles.rkt b/db/articles.rkt index b549dc9..091bd41 100644 --- a/db/articles.rkt +++ b/db/articles.rkt @@ -18,18 +18,18 @@ insert-article) (define (fetch-article conn article-id) - (match-let ([(vector timestamp hash title body) - (query-row conn "SELECT timestamp, hash, title, body FROM diary.articles WHERE article_id = $1" article-id)]) - (make-article article-id (sql-datetime->srfi-date timestamp) hash title body))) + (match-let ([(vector timestamp hash source title body) + (query-row conn "SELECT timestamp, hash, source, title, body FROM diary.articles WHERE article_id = $1" article-id)]) + (make-article article-id (sql-datetime->srfi-date timestamp) hash source title body))) (define (fetch-latest-articles conn limit) (define article-list - (for/list ([(article-id timestamp hash title body) + (for/list ([(article-id timestamp hash source title body) (in-query conn " -SELECT article_id, timestamp, hash, title, body FROM diary.articles ORDER BY timestamp DESC LIMIT $1 +SELECT article_id, timestamp, hash, source, title, body FROM diary.articles ORDER BY timestamp DESC LIMIT $1 " limit)]) - (make-article article-id (sql-datetime->srfi-date timestamp) hash title body))) + (make-article article-id (sql-datetime->srfi-date timestamp) hash source title body))) (define article-tags (for/hash ([(article-id l) (in-query conn @@ -99,12 +99,13 @@ RETURNING tag_id (define (insert-article conn article) (query-exec conn " -INSERT INTO diary.articles(article_id, timestamp, hash, title, body) -VALUES($1, $2, $3, $4, $5) +INSERT INTO diary.articles(article_id, timestamp, hash, source, title, body) +VALUES($1, $2, $3, $4, $5, $6) " (article-id article) (srfi-date->sql-timestamp-tz (article-timestamp article)) (article-hash article) + (article-source article) (article-title article) (article-body article))) @@ -114,14 +115,16 @@ VALUES($1, $2, $3, $4, $5) UPDATE diary.articles SET timestamp = $2, hash = $3, - title = $4, - body = $5 + source = $4, + title = $5, + body = $6 WHERE article_id = $1 AND hash <> $3 " (article-id article) (srfi-date->sql-timestamp-tz (article-timestamp article)) (article-hash article) + (article-source article) (article-title article) (article-body article)))) diff --git a/entities/article.rkt b/entities/article.rkt index 14319d7..4da6cec 100644 --- a/entities/article.rkt +++ b/entities/article.rkt @@ -6,6 +6,7 @@ article-id article-timestamp article-hash + article-source article-title article-body @@ -18,6 +19,7 @@ (struct article ([id : String] [timestamp : date] [hash : String] + [source : String] [title : String] [body : String]) #:type-name Article @@ -34,6 +36,7 @@ (make-article-with-tags (article-id a) (article-timestamp a) (article-hash a) + (article-source a) (article-title a) (article-body a) tags)) diff --git a/readers/article.rkt b/readers/article.rkt index c60de16..2d14639 100644 --- a/readers/article.rkt +++ b/readers/article.rkt @@ -27,6 +27,9 @@ (define hash (hash-ref jse 'hash (thunk (k "hash not found")))) (unless (string? hash) (k "hash must be a string")) + (define source (hash-ref jse 'source (thunk (k "source not found")))) + (unless (string? source) (k "source must be a string")) + (define title (hash-ref jse 'title (thunk (k "title not found")))) (unless (string? title) (k "title must be a string")) @@ -37,7 +40,7 @@ (define body (hash-ref jse 'html (thunk (k "html not found")))) (unless (string? body) (k "html must be a string")) - (make-article-with-tags id timestamp hash title body tags)))) + (make-article-with-tags id timestamp hash source title body tags)))) (: read-article (-> Input-Port (U Article-With-Tags EOF))) (define (read-article in) |