Class: Voluntary::Api::V1::Music::VideosController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/voluntary/api/v1/music/videos_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/voluntary/api/v1/music/videos_controller.rb', line 8

def index
  params[:page] = nil if params[:page] == ''
  params[:per_page] = nil if params[:per_page] == ''
  videos = MusicVideo.liked_by(params[:user_id]).order('likes.created_at DESC').paginate(per_page: params[:per_page] || 10, page: params[:page] || 1)
  
  respond_to do |f|
    f.json {
      render json: {
        current_page: videos.current_page, per_page: videos.per_page, total_entries: videos.total_entries, total_pages: videos.total_pages,
        entries: videos.map do |v| 
          { 
            id: v.id, status: v.status, artist_id: v.artist_id, artist_name: v.artist_name, 
            track_id: v.track_id, track_name: v.track_name, url: v.url, liked_at: v.liked_at.iso8601
          } 
        end,
      }.to_json
    }
  end
end