2026-05-25 12:02:18 -04:00
|
|
|
package query
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/AmanTahiliani/box-box/internal/store"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// NewsItem is the frontend-facing cached briefing shape.
|
|
|
|
|
type NewsItem struct {
|
2026-05-25 15:16:00 -04:00
|
|
|
Source string `json:"source"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
URL string `json:"url"`
|
|
|
|
|
PublishedAt *time.Time `json:"published_at,omitempty"`
|
|
|
|
|
Summary string `json:"summary,omitempty"`
|
|
|
|
|
Category string `json:"category,omitempty"`
|
|
|
|
|
FetchedAt time.Time `json:"fetched_at"`
|
|
|
|
|
OGImageURL string `json:"og_image_url,omitempty"`
|
|
|
|
|
OGDescription string `json:"og_description,omitempty"`
|
|
|
|
|
ReadAt *time.Time `json:"read_at,omitempty"`
|
2026-05-25 12:02:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListNews returns cached briefing items.
|
|
|
|
|
func (s *Service) ListNews(limit int, source string) ([]NewsItem, error) {
|
|
|
|
|
rows, err := s.store.ListNewsItems(limit, source)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
out := make([]NewsItem, 0, len(rows))
|
|
|
|
|
for _, row := range rows {
|
|
|
|
|
out = append(out, NewsItem{
|
2026-05-25 15:16:00 -04:00
|
|
|
Source: row.Source,
|
|
|
|
|
Title: row.Title,
|
|
|
|
|
URL: row.URL,
|
|
|
|
|
PublishedAt: row.PublishedAt,
|
|
|
|
|
Summary: row.Summary,
|
|
|
|
|
Category: row.Category,
|
|
|
|
|
FetchedAt: row.FetchedAt,
|
|
|
|
|
OGImageURL: row.OGImageURL,
|
|
|
|
|
OGDescription: row.OGDescription,
|
|
|
|
|
ReadAt: row.ReadAt,
|
2026-05-25 12:02:18 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return out, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 15:16:00 -04:00
|
|
|
// MarkNewsRead marks a news item as read by URL.
|
|
|
|
|
func (s *Service) MarkNewsRead(url string) error {
|
|
|
|
|
return s.store.MarkNewsItemRead(url)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 12:02:18 -04:00
|
|
|
func NewsItemToStore(item NewsItem) store.NewsItem {
|
|
|
|
|
return store.NewsItem{
|
2026-05-25 15:16:00 -04:00
|
|
|
URL: item.URL,
|
|
|
|
|
Source: item.Source,
|
|
|
|
|
Title: item.Title,
|
|
|
|
|
PublishedAt: item.PublishedAt,
|
|
|
|
|
Summary: item.Summary,
|
|
|
|
|
Category: item.Category,
|
|
|
|
|
FetchedAt: item.FetchedAt,
|
|
|
|
|
OGImageURL: item.OGImageURL,
|
|
|
|
|
OGDescription: item.OGDescription,
|
2026-05-25 12:02:18 -04:00
|
|
|
}
|
|
|
|
|
}
|