Create books via admin
This commit is contained in:
26
slices/admin/actions/books/create.rb
Normal file
26
slices/admin/actions/books/create.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Actions
|
||||
module Books
|
||||
class Create < Admin::Action
|
||||
|
||||
include Deps["repos.book_repo"]
|
||||
|
||||
def handle(req, resp)
|
||||
book_repo.create({
|
||||
name: req.params[:name],
|
||||
book_author: req.params[:book_author],
|
||||
slug: req.params[:slug],
|
||||
content: "",
|
||||
book_status: req.params[:book_status],
|
||||
post_type: "book",
|
||||
published_at: Time.now
|
||||
})
|
||||
|
||||
resp.redirect_to "/admin/books"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -67,5 +67,6 @@ module Admin
|
||||
|
||||
get "/books", to: Auth.call(action: "books.index")
|
||||
patch "/books/:id", to: Auth.call(action: "books.update")
|
||||
post "/books", to: Auth.call(action: "books.create")
|
||||
end
|
||||
end
|
||||
|
@@ -1,7 +1,7 @@
|
||||
module Admin
|
||||
module Repos
|
||||
class BookRepo < Adamantium::Repo[:posts]
|
||||
commands update: :by_pk
|
||||
commands :create, update: :by_pk
|
||||
|
||||
def list_all
|
||||
posts
|
||||
|
@@ -2,6 +2,27 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
|
||||
h1 Admin // Books
|
||||
|
||||
div class="max-w-prose prose dark:prose-invert mx-auto"
|
||||
form action="/admin/books" method="POST"
|
||||
div class="p-2"
|
||||
label class="mr-4" for="name" Name
|
||||
input type="text" name="name" id="name" class="text-gray-900 p-2"
|
||||
div class="p-2"
|
||||
label class="mr-4" for="book_author" Author
|
||||
input type="text" name="book_author" id="book_author" class="text-gray-900 p-2"
|
||||
div class="p-2"
|
||||
label class="mr-4" for="slug" Slug
|
||||
input type="text" name="slug" id="slug" class="text-gray-900 p-2"
|
||||
div class="p-2"
|
||||
label for="book_status"
|
||||
select class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg" name="book_status"
|
||||
option value="read" Read
|
||||
option value="to-read" To Read
|
||||
option value="reading" Reading
|
||||
div class="p-2"
|
||||
button
|
||||
= "Create book"
|
||||
|
||||
|
||||
|
||||
- books.each do |book|
|
||||
div class="w-full"
|
||||
|
10
slices/admin/views/books/create.rb
Normal file
10
slices/admin/views/books/create.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
module Views
|
||||
module Books
|
||||
class Create < Admin::View
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user