diff --git a/api.go b/api.go index a6bb207..8879409 100644 --- a/api.go +++ b/api.go @@ -479,6 +479,19 @@ func APISaveBookmark(c *gin.Context) { c.Writer.WriteHeader(204) } +func APIDeleteBookmark(c *gin.Context) { + bookName := c.Params.ByName("name") + + err := deleteBookmark(bookName, getBookmarkPath()) + + if err != nil { + c.JSON(400, NewError(err)) + return + } + + c.Writer.WriteHeader(204) +} + //APIServeAsset serves the static assets func APIServeAsset(c *gin.Context) { file := fmt.Sprintf( diff --git a/bookmark.go b/bookmark.go index 8c402cc..601364a 100644 --- a/bookmark.go +++ b/bookmark.go @@ -112,3 +112,18 @@ func saveBookmark(objBookmark Bookmark, path string) (int, error) { return 1, nil } + +func deleteBookmark(bookmarkName string, path string) error { + + fileName := bookmarkName + ".json" + + fullFilePath := filepath.FromSlash(path + "/" + fileName) + + err := os.Remove(fullFilePath) + + if err != nil { + return err + } + + return nil +} diff --git a/main.go b/main.go index b9d9715..26451a8 100644 --- a/main.go +++ b/main.go @@ -177,6 +177,7 @@ func startServer() { router.GET("/search/:query", APISearch) router.GET("/bookmarks", APIGetBookmarks) router.POST("/bookmarks/:name", APISaveBookmark) + router.DELETE("/bookmarks/:name", APIDeleteBookmark) fmt.Println("Starting server...") go router.Run(fmt.Sprintf("%v:%v", options.HttpHost, options.HttpPort)) diff --git a/static/css/app.css b/static/css/app.css index fd8d0c2..5220c7e 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -463,3 +463,15 @@ strong.form-control { #sidebar .search{ margin: 5px; } + +.bookmark-list-item .delete-bookmark{ + visibility: hidden; +} + +.bookmark-list-item:hover .delete-bookmark{ + visibility: visible; +} + +.delete-bookmark{ + font-size: 30px; +} diff --git a/static/index.html b/static/index.html index 5aaeaed..9c5a8ff 100644 --- a/static/index.html +++ b/static/index.html @@ -492,9 +492,12 @@