adding summarization and restructure project
This commit is contained in:
54
golang/internal/model/article.go
Normal file
54
golang/internal/model/article.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO docstring
|
||||
type Article struct {
|
||||
Identifier int
|
||||
SourceUrl string
|
||||
PublishDate time.Time
|
||||
FetchDate time.Time
|
||||
Title string
|
||||
Content string
|
||||
AiSummary string
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
type ArticleViewModel struct {
|
||||
Title string
|
||||
PublishDate string
|
||||
SourceUrl string
|
||||
ShortSource string
|
||||
Summary string
|
||||
AiSummarized bool
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
func (a *Article) ViewModel() *ArticleViewModel {
|
||||
summary := a.AiSummary
|
||||
if summary == "" {
|
||||
if len(a.Content) > 200 {
|
||||
summary = a.Content[:200]
|
||||
} else {
|
||||
summary = a.Content
|
||||
}
|
||||
}
|
||||
|
||||
short_url := ""
|
||||
parsedURL, err := url.Parse(a.SourceUrl)
|
||||
if err == nil {
|
||||
short_url = parsedURL.Hostname()
|
||||
}
|
||||
|
||||
return &ArticleViewModel{
|
||||
Title: a.Title,
|
||||
PublishDate: a.PublishDate.Local().Format("02.01.2006"),
|
||||
SourceUrl: a.SourceUrl,
|
||||
ShortSource: short_url,
|
||||
Summary: summary,
|
||||
AiSummarized: a.AiSummary != "",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user