fixing #14
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ArticleViewModelRepository struct {
|
type ArticleViewModelRepository struct {
|
||||||
@@ -29,8 +30,9 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
|
|||||||
var sourceUrl string
|
var sourceUrl string
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
a := model.ArticleViewModel{}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,6 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
|
|||||||
if a.Summary == "" {
|
if a.Summary == "" {
|
||||||
a.Summary = "N/A"
|
a.Summary = "N/A"
|
||||||
}
|
}
|
||||||
|
|
||||||
// short url
|
// short url
|
||||||
parsedURL, err := url.Parse(sourceUrl)
|
parsedURL, err := url.Parse(sourceUrl)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -47,6 +48,8 @@ func (m *ArticleViewModelRepository) All(limit int, offset int) ([]*model.Articl
|
|||||||
} else {
|
} else {
|
||||||
a.ShortSource = ""
|
a.ShortSource = ""
|
||||||
}
|
}
|
||||||
|
// format date
|
||||||
|
a.PublishDate = date.Format("02.01.2006")
|
||||||
|
|
||||||
articleVMs = append(articleVMs, &a)
|
articleVMs = append(articleVMs, &a)
|
||||||
}
|
}
|
||||||
@@ -81,15 +84,17 @@ func (m *ArticleViewModelRepository) Search(query string) ([]*model.ArticleViewM
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
a := &model.ArticleViewModel{}
|
a := &model.ArticleViewModel{}
|
||||||
var sourceUrl string
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// summary
|
// summary
|
||||||
if a.Summary == "" {
|
if a.Summary == "" {
|
||||||
a.Summary = "N/A"
|
a.Summary = "N/A"
|
||||||
}
|
}
|
||||||
|
|
||||||
// short url
|
// short url
|
||||||
parsedURL, err := url.Parse(sourceUrl)
|
parsedURL, err := url.Parse(sourceUrl)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -97,6 +102,8 @@ func (m *ArticleViewModelRepository) Search(query string) ([]*model.ArticleViewM
|
|||||||
} else {
|
} else {
|
||||||
a.ShortSource = ""
|
a.ShortSource = ""
|
||||||
}
|
}
|
||||||
|
// format date
|
||||||
|
a.PublishDate = date.Local().Format("02.01.2006")
|
||||||
|
|
||||||
articleVMs = append(articleVMs, a)
|
articleVMs = append(articleVMs, a)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user