Refactor app in to its own slice

This commit is contained in:
2024-02-17 10:40:36 +11:00
parent b809b132d3
commit a6078f882e
161 changed files with 16176 additions and 193 deletions

View File

@@ -1,31 +0,0 @@
module Adamantium
module Repos
class MovieRepo < Adamantium::Repo[:movies]
def listing
movies.order(Sequel.lit("year desc")).to_a
end
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

View File

@@ -1,9 +0,0 @@
module Adamantium
module Repos
class PodcastRepo < Adamantium::Repo[:podcasts]
def listing
podcasts.order(:name).to_a
end
end
end
end

View File

@@ -1,26 +0,0 @@
module Adamantium
module Repos
class PodcastScrobbleRepo < Adamantium::Repo[:podcast_scrobbles]
commands :create
def exists?(id:)
!!podcast_scrobbles
.where(overcast_id: id)
.one
end
def listing
podcast_scrobbles
.order(Sequel.desc(:listened_at))
.limit(5)
.to_a
end
def for_timemachine(date:)
podcast_scrobbles
.where(listened_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
.to_a
end
end
end
end

View File

@@ -1,223 +0,0 @@
module Adamantium
module Repos
class PostRepo < Adamantium::Repo[:posts]
Sequel.extension :pg_json
Sequel.extension :pg_json_ops
def by_year(year:)
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.where { Sequel.&(Sequel.extract(:year, :published_at) =~ year) }
.combine(:tags)
.to_a
end
def week_posts(limit: nil)
posts
.where(post_type: "post")
.weekly
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def post_listing(limit: nil)
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def home_post_listing(limit: nil)
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.non_weekly
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def photo_listing(limit: nil)
posts
.where(post_type: ["post", "checkin"])
.where(Sequel[:photos].pg_json.array_length > 0)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def places_listing(limit: nil)
posts
.where(post_type: ["checkin", "post"])
.exclude(location: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def books_listing(limit: nil)
posts
.where(post_type: "book")
.published
.order(Sequel.asc(:name))
.limit(limit)
.to_a
end
def bookmark_listing(query: nil)
base = posts
.where(post_type: "bookmark")
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
query ? base.where(Sequel.ilike(:name, "%#{query}%")).to_a : base.to_a
end
def statuses_listing(limit: nil)
posts
.where(post_type: "post", name: nil)
.exclude(Sequel.pg_jsonb_op(:syndication_sources).has_key?("instagram"))
.published
.combine(:tags, :webmentions)
.node(:webmentions) { |webmention|
webmention.published.where(type: "reply")
}
.order(Sequel.desc(:published_at))
.limit(limit)
.to_a
end
def latest_status
posts
.where(name: nil)
.published
.order(Sequel.desc(:published_at))
.limit(1)
.one
end
def last_location
posts
.where(post_type: "checkin")
.published
.order(Sequel.desc(:published_at))
.limit(1)
.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';
posts
.where(post_type: "post")
.published
.where { Sequel.extract(:year, :published_at) < start_date.year }
.where { Sequel.extract(:month, :published_at) >= start_date.month }
.where { Sequel.extract(:month, :published_at) <= end_date.month }
.where { Sequel.extract(:day, :published_at) >= start_date.day }
.where { Sequel.extract(:day, :published_at) <= end_date.day }
.to_a
end
def posts_for_timemachine(date:)
posts
.where(post_type: "post")
.where(published_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
.to_a
end
def bookmarks_for_timemachine(date:)
posts
.where(post_type: "bookmark")
.where(published_at: TimeMath.day.floor(date)...TimeMath.day.advance(date, +1))
.to_a
end
def all_posts
posts
.where(post_type: ["post", "bookmark"])
.published
.order(Sequel.desc(:published_at))
.to_a
end
def for_rss
posts
.where(post_type: ["post", "bookmark"], location: nil)
.exclude(name: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.to_a
end
def statuses_for_rss
posts
.where(post_type: "post", name: nil, location: nil)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.to_a
end
def fetch!(slug)
posts
.published
.combine(:tags, :trips, :webmentions)
.node(:webmentions) { |webmention|
webmention.published.where(type: "reply")
}
.where(slug: slug)
.one!
end
def find!(id)
posts
.by_pk(id)
.one!
end
def post_years
posts
.where(post_type: "post", location: nil)
.exclude(name: nil)
.published
.dataset
.group_and_count(Sequel.extract(:year, :published_at).as(:year))
.order(:year)
.to_a
end
def search(term:)
posts
.where(post_type: "post", location: nil)
.published
.search(term: term)
.combine(:tags)
.order(Sequel.desc(:published_at))
.to_a
end
end
end
end

View File

@@ -1,26 +0,0 @@
module Adamantium
module Repos
class PostTagRepo < Adamantium::Repo[:post_tags]
def posts_tagged(tag:)
tag_id = post_tags
.tags
.where(slug: tag)
.one!
.id
post_ids = post_tags
.where(tag_id: tag_id)
.to_a
.map(&:post_id)
post_tags
.posts
.where(id: post_ids)
.published
.combine(:tags)
.order(Sequel.desc(:published_at))
.to_a
end
end
end
end

View File

@@ -1,16 +0,0 @@
module Adamantium
module Repos
class TagRepo < Adamantium::Repo[:tags]
def fetch!(slug)
tags.where(slug: slug).one!
end
def list
tags
.order(Sequel.function(:lower, :label))
.combine(:posts)
.to_a
end
end
end
end

View File

@@ -1,17 +0,0 @@
module Adamantium
module Repos
class TopTrackRepo < Adamantium::Repo[:top_tracks]
def for_post(id:)
top_tracks
.where(post_id: id)
.to_a
end
def upsert(post_id:, name:, artist:, url:, mb_id:)
top_tracks
.upsert({name: name, artist: artist, url: url, mb_id: mb_id, post_id: post_id},
{target: :post_id, update: {name: name, artist: artist, url: url, mb_id: mb_id, post_id: post_id}})
end
end
end
end

View File

@@ -1,20 +0,0 @@
module Adamantium
module Repos
class TripRepo < Adamantium::Repo[:trips]
def fetch!(id)
trips
.where(id: id)
.combine(posts: :tags)
.one!
end
def list
trips
.published
.order(:start_date)
.reverse
.to_a
end
end
end
end

View File

@@ -1,9 +0,0 @@
module Adamantium
module Repos
class WorkoutRepo < Adamantium::Repo[:workouts]
def list
workouts.order(:published_at).to_a
end
end
end
end