-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move episodes command to the domain layer
- Loading branch information
1 parent
e2cddbf
commit a867bce
Showing
8 changed files
with
55 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
lib/pod/outputs/text/episodes.rb → lib/pod/commands/episodes/output.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Pod | ||
module Commands | ||
module Episodes | ||
class Runner < Pod::Commands::BaseRunner | ||
ALL_COLUMNS = %w[id title release_date duration link].freeze | ||
private_constant :ALL_COLUMNS | ||
|
||
def call(podcast_id, options = {}) | ||
parsed_options = parse_options(options) | ||
|
||
columns = parsed_options["fields"] || ALL_COLUMNS | ||
sql_code = <<~SQL | ||
select #{columns.join(", ")} | ||
from episodes | ||
where podcast_id = #{podcast_id} | ||
SQL | ||
|
||
unless parsed_options["all"] | ||
sql_code << "and archived_at is null\n" | ||
end | ||
|
||
order_by = parsed_options["order_by"] || "id" | ||
sql_code << "order by #{order_by};\n" | ||
|
||
db = Infrastructure::Storage::SQL.new(db: pod_db_dir) | ||
records = db.query(sql_code) | ||
|
||
build_success_response( | ||
details: records.empty? ? :not_found : :records_found, | ||
metadata: {records: records, columns: columns} | ||
) | ||
rescue Infrastructure::Storage::Exceptions::WrongSyntax => exc | ||
cause = exc.message | ||
if cause.include?("no such column") | ||
invalid_column = cause.delete_prefix("no such column: ") | ||
build_failure_response( | ||
details: :invalid_column, | ||
metadata: {invalid_column: invalid_column} | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
spec/pod/outputs/text/episodes_spec.rb → spec/pod/commands/episodes/output_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
spec/pod/commands/episodes_spec.rb → spec/pod/commands/episodes/runner_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters