gopherss/internal/feeds/types.go

76 lines
1.4 KiB
Go
Raw Normal View History

2020-10-17 13:30:30 +00:00
package feeds
import (
"encoding/xml"
"time"
"gorm.io/gorm"
)
type FeedStore struct {
db *gorm.DB
}
type Feed struct {
ID string `gorm:"primaryKey"` // Base64 of FeedURL
Title string
Description string
HomepageURL string
FeedURL string
ImageURL string
LastUpdated *time.Time
Items []Item `gorm:"foreignKey:FeedID"`
UnreadCount int
}
func (feed *Feed) AfterFind(tx *gorm.DB) (err error) {
feed.UnreadCount = 0
for _, item := range feed.Items {
if !item.Read {
feed.UnreadCount++
}
}
return
}
type Item struct {
ID string `gorm:"primaryKey"` // Base64 of GUID
Title string
Description string
Content string
URL string
ImageURL string
LastUpdated *time.Time
Created *time.Time
GUID string
FeedID string
Read bool
Save bool
2020-11-08 19:51:05 +00:00
DeletedAt gorm.DeletedAt
2020-10-17 13:30:30 +00:00
}
type ItemWithFeed struct {
ID string
Title string
URL string
ImageURL string
Created *time.Time
GUID string
FeedID string
Read bool
Save bool
2020-10-17 13:30:30 +00:00
FeedTitle string
FeedHomepageURL string
}
type Opml struct {
XMLName xml.Name `xml:"opml"`
Version string `xml:"version,attr"`
Outlines []Outline `xml:"body>outline"`
}
type Outline struct {
Title string `xml:"title,attr"`
XmlUrl string `xml:"xmlUrl,attr"`
}