diff --git a/config/app.rb b/config/app.rb index 785a1ea..9218278 100644 --- a/config/app.rb +++ b/config/app.rb @@ -20,5 +20,6 @@ class App < Hanami::App end config.shared_app_component_keys += ["redis", "db", "persistence.rom", "shrine"] config.middleware.use Hanami::Middleware::BodyParser, :form + config.middleware.use Rack::MethodOverride end end diff --git a/db/migrate/20231229091551_create_books.rb b/db/migrate/20231229091551_create_books.rb index f1f1575..248deb6 100644 --- a/db/migrate/20231229091551_create_books.rb +++ b/db/migrate/20231229091551_create_books.rb @@ -9,6 +9,7 @@ column :published_date, Date, null: false column :description, :text, null: true column :image_url, String, null: true + column :image_data, :jsonb, null: true column :category, String, null: true column :language, String, null: true column :isbn_10, String, null: true diff --git a/db/migrate/20240116122351_create_storages.rb b/db/migrate/20240116122351_create_storages.rb deleted file mode 100644 index dbc2da3..0000000 --- a/db/migrate/20240116122351_create_storages.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -ROM::SQL.migration do - change do - create_table :storages do - primary_key :id - - column :images, :jsonb - end - end -end diff --git a/lib/libus/persistence/entities/book.rb b/lib/libus/persistence/entities/book.rb new file mode 100644 index 0000000..cad044a --- /dev/null +++ b/lib/libus/persistence/entities/book.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Libus + module Persistence + module Entities + class Book < ROM::Struct + include ImageUploader::Attachment(:image) + end + end + end +end + diff --git a/lib/libus/persistence/relations/books.rb b/lib/libus/persistence/relations/books.rb index 6e659de..5b74c59 100644 --- a/lib/libus/persistence/relations/books.rb +++ b/lib/libus/persistence/relations/books.rb @@ -4,11 +4,13 @@ module Libus module Persistence module Relations class Books < ROM::Relation[:sql] + include ImageUploader::Attachment(:image) schema(:books, infer: true) do associations do belongs_to :author end end + struct_namespace Entities auto_struct(true) end end diff --git a/lib/libus/persistence/relations/storages.rb b/lib/libus/persistence/relations/storages.rb deleted file mode 100644 index 490d0fb..0000000 --- a/lib/libus/persistence/relations/storages.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Libus - module Persistence - module Relations - class Storages < ROM::Relation[:sql] - include ImageUploader::Attachment[:images] - schema(:storages, infer: true) - end - end - end -end - diff --git a/slices/main/actions/books/edit.rb b/slices/main/actions/books/edit.rb new file mode 100644 index 0000000..710ea31 --- /dev/null +++ b/slices/main/actions/books/edit.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Main + module Actions + module Books + class Edit < Main::Action + def handle(request, response) + response.render view, id: request.params[:id] + end + end + end + end +end diff --git a/slices/main/actions/books/update.rb b/slices/main/actions/books/update.rb new file mode 100644 index 0000000..2fcd116 --- /dev/null +++ b/slices/main/actions/books/update.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Main + module Actions + module Books + class Update < Main::Action + def handle(request, response) + puts "na razie nic" + end + end + end + end +end diff --git a/slices/main/config/routes.rb b/slices/main/config/routes.rb index 377d8f3..8ed75a6 100644 --- a/slices/main/config/routes.rb +++ b/slices/main/config/routes.rb @@ -15,6 +15,8 @@ class Routes < Hanami::Routes delete "/logout", to: "sessions.destroy" get '/books', to: 'books.index' + get '/books/:id/edit', to: 'books.edit' + patch '/books/:id', to: 'books.update' get '/storage', to: 'storages.index' scope 'storages' do diff --git a/slices/main/repositories/books.rb b/slices/main/repositories/books.rb index 177ffcb..8992706 100644 --- a/slices/main/repositories/books.rb +++ b/slices/main/repositories/books.rb @@ -16,6 +16,10 @@ def by_isbn(type:, identifier:) books.where(isbn_13: identifier).first end end + + def by_id(id) + books.by_pk(id).one! + end end end end diff --git a/slices/main/templates/books/_avatar.html.erb b/slices/main/templates/books/_avatar.html.erb index 9b6fcdd..ba31035 100644 --- a/slices/main/templates/books/_avatar.html.erb +++ b/slices/main/templates/books/_avatar.html.erb @@ -1,5 +1,5 @@
- +
diff --git a/slices/main/templates/books/edit.html.erb b/slices/main/templates/books/edit.html.erb new file mode 100644 index 0000000..7901f8e --- /dev/null +++ b/slices/main/templates/books/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for book, "/books/#{id}", method: :patch do %> + + + +<% end %> diff --git a/slices/main/templates/books/index.html.erb b/slices/main/templates/books/index.html.erb index 265ed36..2258870 100644 --- a/slices/main/templates/books/index.html.erb +++ b/slices/main/templates/books/index.html.erb @@ -24,7 +24,7 @@ -
+
<%= book.avatar(:sm)%> @@ -41,6 +41,9 @@
<%= book.author.name %>
+ + + <% end %> @@ -52,7 +55,8 @@ Title Genre Author - + + diff --git a/slices/main/views/books/edit.rb b/slices/main/views/books/edit.rb new file mode 100644 index 0000000..d4df37c --- /dev/null +++ b/slices/main/views/books/edit.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Main + module Views + module Books + class Edit < Main::View + include Deps['repositories.books'] + expose :id + expose :book do |id:| + books.by_id(id) + end + end + end + end +end