Skip to content

Commit

Permalink
assign recording to scheduled_show
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Sep 7, 2023
1 parent 8c2f323 commit 4dac10d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/api/my_shows/episodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def create_params
:end_at, :description, :image, :image_filename,
:recurring_interval, :playlist, :time_zone,
:start, :end, :is_guest, :guest, :is_live,
:prerecord_track_id
:prerecord_track_id,
:recording
])
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/show_series/episodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def index

def show
episode = ::ShowSeries.friendly.find(params[:show_series_id]).episodes.friendly.find(params[:id])
render json: episode, include: ['posts', 'labels', 'tracks']
render json: episode, include: ['posts', 'labels', 'tracks', 'recording']
end
end
3 changes: 3 additions & 0 deletions app/controllers/recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class RecordingsController < ApplicationController
def index
authorize! :index, Recording
@recordings = @current_radio.recordings.unscoped.order("file_created_at DESC")
if params[:term]
@recordings = @recordings.where("path ilike (?)", "%#{params.permit(:term)[:term]}%")
end
@recordings = @recordings.page(params[:page])
meta = { page: params[:page], total_pages: @recordings.total_pages.to_i }
render json: @recordings, meta: meta
Expand Down
2 changes: 1 addition & 1 deletion app/models/recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Recording < ActiveRecord::Base
belongs_to :radio
belongs_to :dj, class_name: "User"
belongs_to :track
# belongs_to :show

enum processing_status: ['unprocessed', 'processing', 'processed', 'processing_failed']

default_scope { order(created_at: :desc) }
Expand Down
11 changes: 11 additions & 0 deletions app/models/scheduled_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ScheduledShow < ActiveRecord::Base
belongs_to :playlist
belongs_to :show_series
belongs_to :recurrant_original, class_name: "ScheduledShow"
belongs_to :recording

has_attached_file :image,
styles: { :thumb => "x300", :medium => "x600" },
path: ":attachment/:style/:basename.:extension",
Expand Down Expand Up @@ -41,6 +43,8 @@ class ScheduledShow < ActiveRecord::Base
# after_update :update_recurrences_in_background, if: :recurring_or_recurrence?
# before_destroy :maybe_destroy_recurrences
before_destroy :clear_redis_if_playing

after_update :maybe_process_recording
#
def clear_redis_if_playing
if self.radio.current_show_playing.to_i == self.id
Expand Down Expand Up @@ -318,4 +322,11 @@ def end_at_cannot_be_before_start_at
# def is_original_recurrant?
# !self.recurrant_original_id.present?
# end
#
private
def maybe_process_recording
if self.recording && self.recording.processing_status === 'unprocessed'
ProcessRecordingWorker.perform_later self.recording.id
end
end
end
1 change: 1 addition & 0 deletions app/serializers/scheduled_show_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ScheduledShowSerializer < ActiveModel::Serializer
has_many :djs, embed: :ids, key: :djs
belongs_to :playlist
belongs_to :show_series
belongs_to :recording
has_many :posts, embed: :ids, key: :posts, embed_in_root: true, each_serializer: PostSerializer

def prerecord_track_filename
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRecordingIdToScheduledShow < ActiveRecord::Migration[7.0]
def change
add_column :scheduled_shows, :recording_id, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_08_13_180416) do
ActiveRecord::Schema[7.0].define(version: 2023_09_07_203146) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -350,6 +350,7 @@
t.boolean "is_live", default: false, null: false
t.integer "show_series_id"
t.integer "status", default: 0, null: false
t.integer "recording_id"
t.index ["dj_id"], name: "index_scheduled_shows_on_dj_id"
t.index ["playlist_id"], name: "index_scheduled_shows_on_playlist_id"
t.index ["radio_id"], name: "index_scheduled_shows_on_radio_id"
Expand Down
4 changes: 4 additions & 0 deletions spec/models/scheduled_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@
end
end

describe "archive recordings" do
xit "starts processing the recording after assigning a recording"
end

describe "prerecord_file" do
before do
Sidekiq::Testing.fake!
Expand Down

0 comments on commit 4dac10d

Please sign in to comment.