Toggle showing read items

This commit is contained in:
2020-11-08 19:38:55 +00:00
parent 0a97bef247
commit 614264ebea
4 changed files with 37 additions and 4 deletions

View File

@@ -55,6 +55,17 @@ func (fs *FeedStore) GetUnread() *[]ItemWithFeed {
return items
}
func (fs *FeedStore) GetAll() *[]ItemWithFeed {
items := &[]ItemWithFeed{}
fs.getDB().Table("items").
Select("items.*, feeds.title as feed_title, feeds.homepage_url as feed_homepage_url").
Order("items.created desc, items.title").
Joins("left join feeds on feeds.id = items.feed_id").
Find(items)
return items
}
func (fs *FeedStore) SaveFeed(feed Feed) {
fs.getDB().Omit("Items").Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},

View File

@@ -33,6 +33,10 @@ func (a *API) GetUnread(c *fiber.Ctx) error {
return c.JSON(a.FeedStore.GetUnread())
}
func (a *API) GetAll(c *fiber.Ctx) error {
return c.JSON(a.FeedStore.GetAll())
}
func (a *API) PostRead(c *fiber.Ctx) error {
a.FeedStore.MarkAsRead(c.Params("id"))
return nil

View File

@@ -52,6 +52,7 @@ func Start(port string) error {
app.Get("/api/feed/:id", api.GetFeed)
app.Get("/api/item/:id", api.GetItem)
app.Get("/api/unread", api.GetUnread)
app.Get("/api/all", api.GetAll)
app.Post("/api/read/:id", api.PostRead)
app.Post("/api/read", api.PostReadAll)
app.Get("/api/refresh", api.RefreshAll)