Support deleting feed

This commit is contained in:
2021-02-21 10:29:07 +00:00
parent ab390c9d47
commit 22db062fd9
4 changed files with 27 additions and 0 deletions

View File

@@ -33,6 +33,11 @@ func (fs *FeedStore) GetFeed(id string) *Feed {
return feed
}
func (fs *FeedStore) DeleteFeed(id string) {
fs.getDB().Delete(Feed{ID: id})
fs.getDB().Unscoped().Delete(Item{}, "feed_id = ?", id)
}
func (fs *FeedStore) GetItem(id string) *Item {
item := &Item{}
fs.getDB().Where("id = ?", id).First(item)

View File

@@ -17,6 +17,11 @@ func (a *API) GetFeed(c *fiber.Ctx) error {
return c.JSON(a.FeedStore.GetFeed(c.Params("id")))
}
func (a *API) DeleteFeed(c *fiber.Ctx) error {
a.FeedStore.DeleteFeed(c.Params("id"))
return nil
}
func (a *API) PostFeed(c *fiber.Ctx) error {
url := ""
if err := c.BodyParser(&url); err != nil {

View File

@@ -50,6 +50,7 @@ func Start(port string) error {
app.Get("/api/feeds", api.GetFeeds)
app.Post("/api/feeds", api.PostFeed)
app.Get("/api/feed/:id", api.GetFeed)
app.Delete("/api/feed/:id", api.DeleteFeed)
app.Get("/api/item/:id", api.GetItem)
app.Post("/api/item/:id/save", api.SaveItem)
app.Get("/api/unread", api.GetUnread)