-
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.
Merge pull request #20 from gustavothecoder/move-commands-to-domain-l…
…ayer Move commands to domain layer
- Loading branch information
Showing
23 changed files
with
171 additions
and
163 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/archive.rb → lib/pod/commands/archive/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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Pod | ||
module Commands | ||
module Archive | ||
class Runner < Pod::Commands::BaseRunner | ||
def call(episode_id) | ||
db = Infrastructure::Storage::SQL.new(db: pod_db_dir) | ||
|
||
if db.query("select id from episodes where id = #{episode_id}").empty? | ||
return build_failure_response(details: :not_found) | ||
end | ||
|
||
sql_code = <<~SQL | ||
update episodes | ||
set archived_at = '#{Time.now.iso8601}' | ||
where id = #{episode_id}; | ||
SQL | ||
db.execute(sql_code) | ||
|
||
build_success_response(details: :episode_archived) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
lib/pod/outputs/text/dearchive.rb → lib/pod/commands/dearchive/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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Pod | ||
module Commands | ||
module Dearchive | ||
class Runner < Pod::Commands::BaseRunner | ||
def call(episode_id) | ||
db = Infrastructure::Storage::SQL.new(db: pod_db_dir) | ||
|
||
if db.query("select id from episodes where id = #{episode_id}").empty? | ||
return build_failure_response(details: :not_found) | ||
end | ||
|
||
sql_code = <<~SQL | ||
update episodes | ||
set archived_at = null | ||
where id = #{episode_id}; | ||
SQL | ||
db.execute(sql_code) | ||
|
||
build_success_response(details: :episode_dearchived) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
lib/pod/outputs/text/delete.rb → lib/pod/commands/delete/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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Pod | ||
module Commands | ||
module Delete | ||
class Runner < Pod::Commands::BaseRunner | ||
def call(podcast_id) | ||
db = Infrastructure::Storage::SQL.new(db: pod_db_dir) | ||
|
||
if db.query("select id from podcasts where id = #{podcast_id}").empty? | ||
return build_failure_response(details: :not_found) | ||
end | ||
|
||
sql_code = <<~SQL | ||
delete from episodes | ||
where podcast_id = #{podcast_id}; | ||
SQL | ||
db.execute(sql_code) | ||
|
||
sql_code = <<~SQL | ||
delete from podcasts | ||
where id = #{podcast_id}; | ||
SQL | ||
db.execute(sql_code) | ||
|
||
build_success_response(details: :podcast_deleted) | ||
end | ||
end | ||
end | ||
end | ||
end |
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/archive_spec.rb → spec/pod/commands/archive/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
Oops, something went wrong.