Skip to content

Commit 2a7275c

Browse files
Merge pull request #21 from gustavothecoder/finish-domain-layer
Finish domain layer
2 parents 1d0046c + 80dd81e commit 2a7275c

File tree

29 files changed

+215
-215
lines changed

29 files changed

+215
-215
lines changed

lib/pod/cli.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require "thor"
44

55
require_relative "commands"
6-
require_relative "outputs/text"
76
require_relative "infrastructure/storage/sql"
87
require_relative "infrastructure/shell_interface"
98

@@ -24,9 +23,9 @@ def version
2423
def init
2524
puts "Creating config files..."
2625

27-
result = Pod::Commands::Init.call
26+
result = Pod::Commands::Init::Runner.call
2827

29-
puts Pod::Outputs::Text::Init.call(result)
28+
puts Pod::Commands::Init::Output.call(result)
3029
end
3130

3231
desc "add FEED", "Adds a podcast to the Pod database"
@@ -42,9 +41,9 @@ def add(feed)
4241
desc "podcasts", "List the podcast records"
4342
method_option :fields, type: :array, default: [], desc: "Select the fields that will be displayed."
4443
def podcasts
45-
result = Pod::Commands::Podcasts.call(options)
44+
result = Pod::Commands::Podcasts::Runner.call(options)
4645

47-
puts Pod::Outputs::Text::Podcasts.call(result)
46+
puts Pod::Commands::Podcasts::Output.call(result)
4847
end
4948

5049
desc "episodes PODCAST_ID", "List the podcast episodes"
@@ -61,11 +60,11 @@ def episodes(podcast_id)
6160
method_option :browser, type: :string, default: "firefox", desc: "Choose the browser."
6261
method_option :archive, type: :boolean, default: false, desc: "Archive the episode."
6362
def open(episode_id)
64-
result = Pod::Commands::Open.call(episode_id, options)
63+
result = Pod::Commands::Open::Runner.call(episode_id, options)
6564

6665
Infrastructure::ShellInterface.call(result[:metadata])
6766

68-
puts Pod::Outputs::Text::Open.call(result)
67+
puts Pod::Commands::Open::Output.call(result)
6968
end
7069

7170
desc "archive EPISODE_ID", "Archive the episode"
@@ -91,17 +90,17 @@ def delete(podcast_id)
9190

9291
desc "sync PODCAST_ID", "Sync the podcast."
9392
def sync(podcast_id)
94-
result = Pod::Commands::Sync.call(podcast_id)
93+
result = Pod::Commands::Sync::Runner.call(podcast_id)
9594

96-
puts Pod::Outputs::Text::Sync.call(result)
95+
puts Pod::Commands::Sync::Output.call(result)
9796
end
9897

9998
desc "update PODCAST_ID", "Update the podcast attributes."
10099
method_option :feed, type: :string, default: "", desc: "Define the podcast feed."
101100
def update(podcast_id)
102-
result = Pod::Commands::Update.call(podcast_id, options)
101+
result = Pod::Commands::Update::Runner.call(podcast_id, options)
103102

104-
puts Pod::Outputs::Text::Update.call(result)
103+
puts Pod::Commands::Update::Output.call(result)
105104
end
106105
end
107106
end

lib/pod/commands.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
require_relative "commands/delete/output"
1313
require_relative "commands/episodes/runner"
1414
require_relative "commands/episodes/output"
15-
16-
require_relative "commands/init"
17-
require_relative "commands/podcasts"
18-
require_relative "commands/open"
19-
require_relative "commands/sync"
20-
require_relative "commands/update"
15+
require_relative "commands/init/runner"
16+
require_relative "commands/init/output"
17+
require_relative "commands/open/runner"
18+
require_relative "commands/open/output"
19+
require_relative "commands/podcasts/runner"
20+
require_relative "commands/podcasts/output"
21+
require_relative "commands/sync/runner"
22+
require_relative "commands/sync/output"
23+
require_relative "commands/update/runner"
24+
require_relative "commands/update/output"
2125

2226
module Pod
2327
module Commands; end

lib/pod/commands/init.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/pod/outputs/text/init.rb renamed to lib/pod/commands/init/output.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
module Pod
4-
module Outputs
5-
module Text
6-
class Init < ::Pod::Commands::BaseOutput
4+
module Commands
5+
module Init
6+
class Output < ::Pod::Commands::BaseOutput
77
def call
88
case @context[:details]
99
when :already_initialized

lib/pod/commands/init/runner.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require "fileutils"
4+
5+
module Pod
6+
module Commands
7+
module Init
8+
class Runner < Pod::Commands::BaseRunner
9+
def call
10+
return build_failure_response(details: :home_not_found) if home_dir.nil?
11+
12+
return build_failure_response(details: :already_initialized) if Dir.exist?(pod_config_dir)
13+
14+
FileUtils.mkdir_p(pod_config_dir)
15+
16+
db = Infrastructure::Storage::SQL.new(db: pod_db_dir)
17+
db.execute <<-SQL
18+
create table podcasts (
19+
id integer primary key,
20+
name text not null,
21+
description text,
22+
feed text not null unique,
23+
website text
24+
);
25+
SQL
26+
db.execute <<-SQL
27+
create table episodes (
28+
id integer primary key,
29+
title text not null,
30+
release_date text,
31+
duration text,
32+
link text not null,
33+
archived_at text,
34+
external_id string unique,
35+
podcast_id integer not null,
36+
foreign key(podcast_id) references podcasts(id)
37+
);
38+
SQL
39+
40+
build_success_response(details: :successfully_initialized)
41+
rescue SystemCallError, Infrastructure::Storage::Exceptions::CantStartConnection
42+
build_failure_response(details: :cannot_create_initial_config)
43+
end
44+
end
45+
end
46+
end
47+
end

lib/pod/commands/open.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/pod/outputs/text/open.rb renamed to lib/pod/commands/open/output.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
module Pod
4-
module Outputs
5-
module Text
6-
class Open < ::Pod::Commands::BaseOutput
4+
module Commands
5+
module Open
6+
class Output < ::Pod::Commands::BaseOutput
77
def call
88
case @context[:details]
99
when :not_found

lib/pod/commands/open/runner.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Pod
2+
module Commands
3+
module Open
4+
class Runner < Pod::Commands::BaseRunner
5+
def call(episode_id, options = {})
6+
parsed_options = parse_options(options)
7+
8+
db = Infrastructure::Storage::SQL.new(db: pod_db_dir)
9+
episode = db.query("select link from episodes where id = #{episode_id}")[0]
10+
return build_failure_response(details: :not_found) if episode.nil?
11+
12+
browser = parsed_options["browser"] || "firefox"
13+
cmd = "#{browser} #{episode.link}"
14+
cmd << " && bundle exec pod archive #{episode_id}" if parsed_options["archive"]
15+
16+
build_success_response(
17+
details: :episode_found,
18+
metadata: {cmd: cmd}
19+
)
20+
end
21+
end
22+
end
23+
end
24+
end

lib/pod/commands/podcasts.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/pod/outputs/text/podcasts.rb renamed to lib/pod/commands/podcasts/output.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
module Pod
4-
module Outputs
5-
module Text
6-
class Podcasts < ::Pod::Commands::BaseOutput
4+
module Commands
5+
module Podcasts
6+
class Output < ::Pod::Commands::BaseOutput
77
def call
88
case @context[:details]
99
when :records_found

0 commit comments

Comments
 (0)