Favorite and playlist models
This commit is contained in:
parent
9531230f6e
commit
9558f720ca
|
@ -43,6 +43,36 @@ class UserController < ApplicationController
|
|||
render :json => @res
|
||||
end
|
||||
|
||||
def fav
|
||||
@res = {status: 'fail'}
|
||||
check = check_auth(params)
|
||||
|
||||
if check == true
|
||||
fav = Favorite.new
|
||||
if not params[:artist].nil?
|
||||
artist = Artist.find(params[:artist]);
|
||||
unless artist.nil?
|
||||
fav.artist_id = artist.id
|
||||
res[:status] = 'added'
|
||||
end
|
||||
elsif not params[:album].nil?
|
||||
album = Album.find(params[:album]);
|
||||
unless album.nil?
|
||||
fav.album_id = album.id
|
||||
res[:status] = 'added'
|
||||
end
|
||||
elsif not params[:track].nil?
|
||||
track = Track.find(params[:track]);
|
||||
unless track.nil?
|
||||
fav.track_id = track.id
|
||||
res[:status] = 'added'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render :json => @res
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_auth params
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class Favorite < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :artist
|
||||
belongs_to :album
|
||||
belongs_to :track
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class Playlist < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
has_many :playlist_tracks
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class PlaylistItem < ActiveRecord::Base
|
||||
belongs_to :playlist
|
||||
belongs_to :track
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
class CreateFavorites < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :favorites do |t|
|
||||
t.integer :user_id
|
||||
t.integer :artist_id
|
||||
t.integer :album_id
|
||||
t.integer :track_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :favorites
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class CreatePlaylists < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :playlists do |t|
|
||||
t.integer :user_id
|
||||
t.string :name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :playlists
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class CreatePlaylistItems < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :playlist_items do |t|
|
||||
t.integer :playlist_id
|
||||
t.integer :track_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :playlist_items
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
artist_id: 1
|
||||
album_id: 1
|
||||
track_id: 1
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
artist_id: 1
|
||||
album_id: 1
|
||||
track_id: 1
|
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
playlist_id: 1
|
||||
track_id: 1
|
||||
|
||||
two:
|
||||
playlist_id: 1
|
||||
track_id: 1
|
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
name: MyString
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PlaylistItemTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PlaylistTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue