Show movies watched on weekly posts
This commit is contained in:
22
app/decorators/movies/decorator.rb
Normal file
22
app/decorators/movies/decorator.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
# auto_register: false
|
||||
|
||||
module Adamantium
|
||||
module Decorators
|
||||
module Movies
|
||||
class Decorator < SimpleDelegator
|
||||
|
||||
include Deps["clients.omdb"]
|
||||
|
||||
def poster
|
||||
omdb_record.poster
|
||||
end
|
||||
|
||||
def omdb_record
|
||||
@omdb_record ||= omdb.call(imdb_id: imdb_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -10,6 +10,24 @@ module Adamantium
|
||||
def by_title_and_year(title:, year:)
|
||||
movies.where(title: title, year: year).one
|
||||
end
|
||||
|
||||
def from_the_archives(start_date:, end_date:)
|
||||
# SELECT * FROM posts
|
||||
# WHERE EXTRACT(month FROM "published_at") >= 2
|
||||
# WHERE EXTRACT(month FROM "published_at") <= 2+
|
||||
# AND EXTRACT(day FROM "published_at") > 20
|
||||
# AND EXTRACT(day FROM "published_at") < 27
|
||||
# AND post_type = 'post';
|
||||
|
||||
movies
|
||||
.where { Sequel.extract(:year, :watched_at) >= start_date.year }
|
||||
.where { Sequel.extract(:year, :watched_at) <= start_date.year }
|
||||
.where { Sequel.extract(:month, :watched_at) >= start_date.month }
|
||||
.where { Sequel.extract(:month, :watched_at) <= end_date.month }
|
||||
.where { Sequel.extract(:day, :watched_at) >= start_date.day }
|
||||
.where { Sequel.extract(:day, :watched_at) <= end_date.day }
|
||||
.to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -40,6 +40,16 @@ article class="h-entry"
|
||||
div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex gap-4"
|
||||
div class="grow" hx-get="/post/top_tracks/#{post.slug}" hx-trigger="load"
|
||||
|
||||
- if past_movies.count > 0
|
||||
div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 mb-4"
|
||||
h3 class="text-xl" Movies watched
|
||||
div class="flex gap-4 pb-4 mt-4"
|
||||
- past_movies.map do |movie|
|
||||
a href=movie.url
|
||||
figure
|
||||
img class="rounded hover:opacity-80" src=movie.poster
|
||||
figcaption= movie.title
|
||||
hr
|
||||
- if text_posts.count > 0
|
||||
div class="block grow bg-blue-100 dark:bg-blue-600 rounded px-4 py-2 mb-12"
|
||||
p class="text-sm mb-0" This week, years ago
|
||||
|
@@ -4,7 +4,7 @@ module Adamantium
|
||||
module Views
|
||||
module Posts
|
||||
class Show < Adamantium::View
|
||||
include Deps["repos.post_repo"]
|
||||
include Deps["repos.post_repo", "repos.movie_repo"]
|
||||
|
||||
expose :post do |slug:|
|
||||
Decorators::Posts::Decorator.new(post_repo.fetch!(slug))
|
||||
@@ -17,6 +17,13 @@ module Adamantium
|
||||
posts.map { |p| Decorators::Posts::Decorator.new(p) }
|
||||
end
|
||||
|
||||
expose :past_movies do |post|
|
||||
start_date = TimeMath.week.floor(post.published_at)
|
||||
end_date = TimeMath.week.ceil(post.published_at)
|
||||
movies = movie_repo.from_the_archives(start_date: start_date, end_date: end_date)
|
||||
movies.map { |p| Decorators::Movies::Decorator.new(p) }
|
||||
end
|
||||
|
||||
expose :text_posts do |past_posts|
|
||||
past_posts.reject(&:photos?)
|
||||
end
|
||||
|
Reference in New Issue
Block a user