Files
crowsnest/internal/model/article.go

44 lines
793 B
Go
Raw Normal View History

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
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,
2025-01-03 14:39:20 +01:00
PublishDate: a.PublishDate.Local().Format("02.01.2006 15:04"),
2025-01-02 16:21:02 +01:00
SourceUrl: a.SourceUrl,
Summary: summary,
}
2024-12-27 03:25:44 +01:00
}