Update trips

This commit is contained in:
2023-05-10 20:39:22 +10:00
parent c4223aab31
commit 2fce0d3967
12 changed files with 384 additions and 63 deletions

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class Update < Admin::Action
include Deps["commands.trips.update"]
def handle(req, res)
id = req.params[:id]
trip = req.params[:trip]
update.call(id: id, trip: trip)
res.redirect_to "/admin/trips/#{id}"
end
end
end
end
end

View File

@@ -0,0 +1,16 @@
module Admin
module Commands
module Trips
class Update
include Dry::Monads[:result]
include Deps["repos.trip_repo"]
def call(id:, trip:)
trip_repo.update(id, trip)
Success()
end
end
end
end
end

View File

@@ -4,12 +4,20 @@ module Admin
commands :create
def list
trips.order(:start_date).to_a
trips
.order(:start_date)
.to_a
end
def fetch(id)
trips.where(id: id).one
end
def update(id, trip)
trips
.where(id: id)
.update(trip)
end
end
end
end

View File

@@ -1,6 +1,22 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Admin // Trips // #{trip.name}
div class="max-w-prose mx-auto mb-8 border-gray-400 border-b-4"
form action="/admin/trips/#{trip.id}" method="POST"
input type="hidden" name="method" value="_put"
div class="mb-4"
label class="text-gray-800 dark:text-gray-200 mr-2" for="name" Name:
input class="text-gray-800 p-1 border border-gray-400" type="text" id="name" name="trip[name]" value=trip.name
div class="mb-4"
label class="text-gray-800 dark:text-gray-200 mr-2" for="subtitle" Subtitle:
input class="text-gray-800 p-1 border border-gray-400" type="text" id="subtitle" name="trip[subtitle]" value=trip.subtitle
div class="mb-4"
button class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" type="submit"
= "Update"
div class="max-w-prose mx-auto"
- posts.each do |post|
== render "shared/post", post: post, trip_id: trip.id, added: post.trips.map(&:id).include?(trip.id)