add single article page
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
// TODO docstring
|
||||
type Article struct {
|
||||
Identifier int
|
||||
Id int
|
||||
SourceUrl string
|
||||
PublishDate time.Time
|
||||
FetchDate time.Time
|
||||
@@ -18,14 +18,23 @@ type Article struct {
|
||||
|
||||
// TODO docstring
|
||||
type ArticleViewModel struct {
|
||||
Id int
|
||||
Title string
|
||||
PublishDate string
|
||||
SourceUrl string
|
||||
ShortSource string
|
||||
Summary string
|
||||
AiSummarized bool
|
||||
}
|
||||
|
||||
type ArticlePageViewModel struct {
|
||||
SourceUrl string
|
||||
ShortSource string
|
||||
PublishDate string
|
||||
Title string
|
||||
Content string
|
||||
AiSummary string
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
func (a *Article) ViewModel() *ArticleViewModel {
|
||||
summary := a.AiSummary
|
||||
@@ -44,11 +53,33 @@ func (a *Article) ViewModel() *ArticleViewModel {
|
||||
}
|
||||
|
||||
return &ArticleViewModel{
|
||||
Id: a.Id,
|
||||
Title: a.Title,
|
||||
PublishDate: a.PublishDate.Local().Format("02.01.2006"),
|
||||
SourceUrl: a.SourceUrl,
|
||||
ShortSource: short_url,
|
||||
Summary: summary,
|
||||
AiSummarized: a.AiSummary != "",
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Article) PageViewModel() *ArticlePageViewModel {
|
||||
summary := a.AiSummary
|
||||
if summary == "" {
|
||||
summary = "N/A"
|
||||
}
|
||||
|
||||
short_url := ""
|
||||
parsedURL, err := url.Parse(a.SourceUrl)
|
||||
if err == nil {
|
||||
short_url = parsedURL.Hostname()
|
||||
}
|
||||
|
||||
return &ArticlePageViewModel{
|
||||
SourceUrl: a.SourceUrl,
|
||||
ShortSource: short_url,
|
||||
Title: a.Title,
|
||||
PublishDate: a.PublishDate.Local().Format("02.01.2006 15:04"),
|
||||
Content: a.Content,
|
||||
AiSummary: summary,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user