This commit is contained in:
2025-01-21 15:54:41 +01:00
parent dcba0ad890
commit cbc5bec053

View File

@@ -5,6 +5,7 @@ import (
"database/sql"
"net/url"
"strings"
"time"
)
type ArticleViewModelRepository struct {
@@ -29,8 +30,9 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
var sourceUrl string
for rows.Next() {
a := model.ArticleViewModel{}
var date time.Time
err := rows.Scan(&a.Id, &a.Title, &sourceUrl, &a.PublishDate, &a.Summary)
err := rows.Scan(&a.Id, &a.Title, &sourceUrl, &date, &a.Summary)
if err != nil {
return nil, err
}
@@ -39,7 +41,6 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
if a.Summary == "" {
a.Summary = "N/A"
}
// short url
parsedURL, err := url.Parse(sourceUrl)
if err == nil {
@@ -47,6 +48,8 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
} else {
a.ShortSource = ""
}
// format date
a.PublishDate = date.Format("02.01.2006")
articleVMs = append(articleVMs, &a)
}
@@ -81,15 +84,17 @@ func (m *ArticleViewModelRepository) Search(query string) ([]*model.ArticleViewM
for rows.Next() {
a := &model.ArticleViewModel{}
var sourceUrl string
err := rows.Scan(&a.Id, &a.Title, &sourceUrl, &a.PublishDate, &a.Summary)
var date time.Time
err := rows.Scan(&a.Id, &a.Title, &sourceUrl, &date, &a.Summary)
if err != nil {
return nil, err
}
// summary
if a.Summary == "" {
a.Summary = "N/A"
}
// short url
parsedURL, err := url.Parse(sourceUrl)
if err == nil {
@@ -97,6 +102,8 @@ func (m *ArticleViewModelRepository) Search(query string) ([]*model.ArticleViewM
} else {
a.ShortSource = ""
}
// format date
a.PublishDate = date.Local().Format("02.01.2006")
articleVMs = append(articleVMs, a)
}