package viewmodel

import "crowsnest/internal/model"


type ArticleViewModel struct {
    Title       string
    Author      string
    PublishDate string
    SourceUrl   string
    Summary     string
}

func NewArticleViewModel(a *model.Article) *ArticleViewModel {
    summary := a.Content
    if len(a.Content) > 200 {
        summary = summary[:200]
    }

    return &ArticleViewModel{
        Title: a.Title,
        Author: a.Author,
        PublishDate: a.PublishDate.Local().Format("02.01.2006 03:04"),
        SourceUrl: a.SourceUrl,
        Summary: summary,
    }
}
