2024-12-27 03:25:44 +01:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-02 16:21:02 +01:00
|
|
|
|
2024-12-28 01:40:30 +01:00
|
|
|
// TODO docstring
|
2024-12-27 03:25:44 +01:00
|
|
|
type Article struct {
|
2025-01-03 01:00:06 +01:00
|
|
|
Identifier int
|
2024-12-27 22:34:43 +01:00
|
|
|
SourceUrl string
|
|
|
|
|
PublishDate time.Time
|
|
|
|
|
FetchDate time.Time
|
|
|
|
|
Title string
|
|
|
|
|
Content string
|
2024-12-29 00:56:47 +01:00
|
|
|
Author string
|
2024-12-27 03:25:44 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-02 16:21:02 +01:00
|
|
|
// TODO docstring
|
|
|
|
|
type ArticleViewModel struct {
|
|
|
|
|
Title string
|
|
|
|
|
Author string
|
|
|
|
|
PublishDate string
|
|
|
|
|
SourceUrl string
|
|
|
|
|
Summary string
|
|
|
|
|
}
|
2024-12-27 22:34:43 +01:00
|
|
|
|
2025-01-02 16:21:02 +01:00
|
|
|
|
|
|
|
|
// TODO docstring
|
|
|
|
|
func (a *Article) ViewModel() *ArticleViewModel {
|
|
|
|
|
summary := a.Content
|
|
|
|
|
if len(a.Content) > 300 {
|
|
|
|
|
summary = summary[:300]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &ArticleViewModel{
|
|
|
|
|
Title: a.Title,
|
|
|
|
|
Author: a.Author,
|
|
|
|
|
PublishDate: a.PublishDate.Local().Format("02.01.2006 03:04"),
|
|
|
|
|
SourceUrl: a.SourceUrl,
|
|
|
|
|
Summary: summary,
|
|
|
|
|
}
|
2024-12-27 03:25:44 +01:00
|
|
|
}
|