diff --git a/config/routes.rb b/config/routes.rb index 7612534..f499952 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,7 @@ module Adamantium get "/bookmarks", to: "bookmarks.index" delete "/bookmarks/:id", to: "bookmarks.delete" post "/bookmarks/cache/:id", to: "bookmarks.cache" + post "/bookmarks/:id/archive", to: "bookmarks.archive" end end end diff --git a/slices/admin/actions/bookmarks/archive.rb b/slices/admin/actions/bookmarks/archive.rb new file mode 100644 index 0000000..1db2f51 --- /dev/null +++ b/slices/admin/actions/bookmarks/archive.rb @@ -0,0 +1,16 @@ +module Admin + module Actions + module Bookmarks + class Archive < Action + + include Deps["repos.bookmark_repo"] + + def handle(req, res) + bookmark_id = req.params[:id] + + bookmark_repo.archive(id: bookmark_id) + end + end + end + end +end \ No newline at end of file diff --git a/slices/admin/repos/bookmark_repo.rb b/slices/admin/repos/bookmark_repo.rb index b94d8d9..4c2b6ed 100644 --- a/slices/admin/repos/bookmark_repo.rb +++ b/slices/admin/repos/bookmark_repo.rb @@ -15,6 +15,10 @@ module Admin posts.where(id: id).delete end + def archive(id:) + posts.where(id: id).update(published_at: nil) + end + def update(id:, cached_content:) posts.where(id: id).update(cached_content: cached_content) end diff --git a/slices/admin/templates/bookmarks/index.html.slim b/slices/admin/templates/bookmarks/index.html.slim index f95cb19..5c03515 100644 --- a/slices/admin/templates/bookmarks/index.html.slim +++ b/slices/admin/templates/bookmarks/index.html.slim @@ -24,6 +24,7 @@ div class="max-w-prose mx-auto" = bookmark.published_at&.strftime("%d %b %Y") td button hx-delete="/admin/bookmarks/#{bookmark.id}" hx-target="#bookmark-#{bookmark.id}" delete + button hx-post="/admin/bookmarks/#{bookmark.id}/archive" archive div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"