Add trips

This commit is contained in:
2023-05-09 21:51:44 +10:00
parent ebdf051b82
commit 7988ffc76d
37 changed files with 651 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class AddPost < Admin::Action
include Deps["commands.trips.add_post"]
def handle(req, res)
add_post.call(post_id: req.params[:post_id], trip_id: req.params[:trip_id])
end
end
end
end
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class Create < Admin::Action
include Deps["commands.trips.create"]
def handle(req, res)
create.call(trip: req.params[:trip])
end
end
end
end
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class Index < Admin::Action
def handle(req, res)
end
end
end
end
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class New < Admin::Action
def handle(req, res)
end
end
end
end
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module Admin
module Actions
module Trips
class Show < Admin::Action
include Deps["views.trips.show"]
def handle(req, res)
res.render show, id: req.params[:id]
end
end
end
end
end

View File

@@ -0,0 +1,16 @@
module Admin
module Commands
module Trips
class AddPost
include Dry::Monads[:result]
include Deps["repos.post_trip_repo"]
def call(trip_id:, post_id:)
post_trip_repo.create(trip_id: trip_id, post_id: post_id)
Success()
end
end
end
end
end

View File

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

View File

@@ -46,6 +46,12 @@ module Admin
def archive(id:)
posts.where(id: id).update(published_at: nil)
end
def created_between(start_date, end_date)
posts
.combine(:trips)
.published_between(start_date, end_date)
end
end
end
end

View File

@@ -0,0 +1,7 @@
module Admin
module Repos
class PostTripRepo < Adamantium::Repo[:post_trips]
commands :create
end
end
end

View File

@@ -0,0 +1,15 @@
module Admin
module Repos
class TripRepo < Adamantium::Repo[:trips]
commands :create
def list
trips.order(:start_date).to_a
end
def fetch(id)
trips.where(id: id).one
end
end
end
end

View File

@@ -15,6 +15,8 @@ div class="max-w-prose mx-auto prose dark:prose-invert"
a href="/admin/tags/merge" Merge tags
li
a href="/admin/bookmarks" Bookmarks
li
a href="/admin/trips" Trips
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -0,0 +1,15 @@
div class="mb-8 h-entry"
- if !added
button class="text-blue-600" hx-post="/admin/trips/add_post" hx-vals='{"trip_id": "#{trip_id}", "post_id": "#{post.id}"}'
= "Add to trip"
h3 class="text-xl font-semibold text-blue-600 mb-2"
a class="border-b-2 border-transparent hover:border-blue-600 hover:border-b-2" href="/post/#{post.slug}"
== post.content
div class="e-content prose-p:mb-0 prose-img:my-2 prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline p-name text-base prose prose-ul:list-none prose-ul:pl-0 prose-li:pl-0 text-gray-800 dark:text-gray-200 prose-a:dark:text-gray-100"
div class="grid gap-4 grid-flow-row grid-cols-4 grid-rows-1"
-post.photos.each do |photo|
img class="w-44 h-44 object-cover rounded" src=photo["value"]
p class="text-sm text-blue-400"
a href="/post/#{post.slug}"
= post.published_at

View File

@@ -0,0 +1,17 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Admin // Trips
div class="max-w-prose mx-auto"
a class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" href="/admin/trips/new" Add trip
ul class="mt-4 mb-12"
- trips.each do |trip|
li class="dark:text-gray-200 text-gray-600"
a href="/admin/trips/#{trip.id}"
= "#{trip.name} (#{trip.start_date} - #{trip.end_date})"
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -0,0 +1,27 @@
div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:text-gray-200"
h1 Admin // Trips
div class="max-w-prose mx-auto"
- if errors
div class="text-gray-100 dark:text-gray-100 bg-pink-100 dark:bg-pink-600 rounded px-4 py-2 mb-12"
p Errors:
- errors.each do |error|
li = "#{error[1].join(",")}"
form method="POST" action="/admin/trips"
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]"
div class="mb-4"
label class="text-gray-800 dark:text-gray-200 mr-2" for="start_date" Start date:
input class="text-gray-800 p-1 border border-gray-400" type="date" id="start_date" name="trip[start_date]"
div class="mb-4"
label class="text-gray-800 dark:text-gray-200 mr-2" for="end_date" End date:
input class="text-gray-800 p-1 border border-gray-400" type="date" id="end_date" name="trip[end_date]"
div class="mb-4"
button class="rounded bg-blue-100 hover:bg-blue-200 text-blue-600 px-2 hover:cursor-pointer" type="submit"
= "Create"
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -0,0 +1,8 @@
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"
- posts.each do |post|
== render "shared/post", post: post, trip_id: trip.id, added: post.trips.map(&:id).include?(trip.id)
div class="max-w-screen-md mx-auto border-t-4 border-solid border-gray-400 dark:border-gray-600"

View File

@@ -0,0 +1,14 @@
module Admin
module Views
module Trips
class Index < Admin::View
include Deps["repos.trip_repo"]
expose :trips do
trip_repo.list
end
end
end
end
end

View File

@@ -0,0 +1,11 @@
module Admin
module Views
module Trips
class New < Admin::View
expose :errors do
nil
end
end
end
end
end

View File

@@ -0,0 +1,18 @@
module Admin
module Views
module Trips
class Show < Admin::View
include Deps["repos.trip_repo", "repos.post_repo"]
expose :trip do |id:|
trip_repo.fetch(id)
end
expose :posts do |trip|
post_repo.created_between(trip.start_date, trip.end_date)
end
end
end
end
end