Class: Podrb::Commands::Archive::Runner

Inherits:
BaseRunner
  • Object
show all
Defined in:
lib/podrb/commands/archive/runner.rb

Instance Method Summary collapse

Methods inherited from BaseRunner

call

Instance Method Details

#call(episode_id) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/podrb/commands/archive/runner.rb', line 7

def call(episode_id)
  db = Infrastructure::Storage::SQL.new(db: podrb_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