VRFS-102 - added models for musician/band likes
This commit is contained in:
parent
be5600e675
commit
05d8278a05
|
|
@ -29,6 +29,7 @@ require "jam_ruby/models/join_request"
|
|||
require "jam_ruby/models/band"
|
||||
require "jam_ruby/models/band_recording"
|
||||
require "jam_ruby/models/band_invitation"
|
||||
require "jam_ruby/models/band_liker"
|
||||
require "jam_ruby/models/band_follower"
|
||||
require "jam_ruby/models/band_musician"
|
||||
require "jam_ruby/models/connection"
|
||||
|
|
@ -40,6 +41,8 @@ require "jam_ruby/models/friend_request"
|
|||
require "jam_ruby/models/instrument"
|
||||
require "jam_ruby/models/musician_instrument"
|
||||
require "jam_ruby/models/connection_track"
|
||||
require "jam_ruby/models/user_liker"
|
||||
require "jam_ruby/models/user_like"
|
||||
require "jam_ruby/models/user_follower"
|
||||
require "jam_ruby/models/user_following"
|
||||
require "jam_ruby/models/user_favorite"
|
||||
|
|
|
|||
|
|
@ -16,32 +16,38 @@ module JamRuby
|
|||
|
||||
# recordings
|
||||
has_many :band_recordings, :class_name => "JamRuby::BandRecording", :foreign_key => "band_id"
|
||||
has_many :recordings, :through => :band_recordings, :class_name => "JamRuby::Recording"
|
||||
has_many :recordings, :through => :band_recordings, :class_name => "JamRuby::Recording", :foreign_key => "recording_id"
|
||||
|
||||
# likers
|
||||
has_many :likers, :class_name => "JamRuby::BandLiker", :foreign_key => "band_id"
|
||||
has_many :inverse_likers, :through => :likers, :class_name => "JamRuby::User", :foreign_key => "liker_id"
|
||||
|
||||
# followers
|
||||
has_many :followers, :class_name => "JamRuby::BandFollower", :foreign_key => "band_id"
|
||||
has_many :inverse_followers, :through => :followers, :source => :user, :class_name => "JamRuby::Band", :foreign_key => "follower_id"
|
||||
|
||||
# music_sessions
|
||||
has_many :music_sessions, :class_name => "JamRuby::MusicSession", :foreign_key => "band_id"
|
||||
|
||||
def photo_url
|
||||
# TODO: move image path to config
|
||||
@photo_url = "http://www.jamkazam.com/images/bands/photos/#{self.id}.gif"
|
||||
end
|
||||
|
||||
def logo_url
|
||||
# TODO: move image path to config
|
||||
@logo_url = "http://www.jamkazam.com/images/bands/logos/#{self.id}.gif"
|
||||
end
|
||||
has_many :inverse_followers, :through => :followers, :class_name => "JamRuby::User", :foreign_key => "follower_id"
|
||||
|
||||
# invitations
|
||||
has_many :invitations, :inverse_of => :band, :class_name => "JamRuby::BandInvitation", :foreign_key => "band_id"
|
||||
|
||||
# music_sessions
|
||||
has_many :music_sessions, :class_name => "JamRuby::MusicSession", :foreign_key => "band_id"
|
||||
|
||||
def liker_count
|
||||
return self.likers.size
|
||||
end
|
||||
|
||||
def follower_count
|
||||
return self.followers.size
|
||||
end
|
||||
|
||||
def recording_count
|
||||
return self.recordings.size
|
||||
end
|
||||
|
||||
def session_count
|
||||
return self.music_sessions.size
|
||||
end
|
||||
|
||||
def location
|
||||
# TODO: implement a single string version of location;
|
||||
# this will be indexed into elasticsearch and returned in search
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
module JamRuby
|
||||
class BandLiker < ActiveRecord::Base
|
||||
|
||||
self.table_name = "bands_likers"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :band, :class_name => "JamRuby::Band", :foreign_key => "band_id", :inverse_of => :inverse_band_likers
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_id", :inverse_of => :band_likers
|
||||
end
|
||||
end
|
||||
|
|
@ -10,10 +10,15 @@ module JamRuby
|
|||
has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "recordings_genres"
|
||||
|
||||
# favorites
|
||||
has_and_belongs_to_many :user_favorites, :class_name => "JamRuby::UserFavorite", :join_table => "users_favorites"
|
||||
has_many :favorites, :class_name => "JamRuby::UserFavorite", :foreign_key => "recording_id"
|
||||
has_many :inverse_favorites, :through => :favorites, :source => :recording, :class_name => "JamRuby::Recording"
|
||||
|
||||
validates :description, presence: true, length: { maximum: 200 }
|
||||
|
||||
def favorite_count
|
||||
return self.favorites.size
|
||||
end
|
||||
|
||||
def self.save(id, is_public, description, genres, updater_id, owner_id, is_band)
|
||||
|
||||
creator = User.find(updater_id)
|
||||
|
|
|
|||
|
|
@ -30,19 +30,31 @@ module JamRuby
|
|||
|
||||
# followers
|
||||
has_many :followers, :class_name => "JamRuby::UserFollower", :foreign_key => "user_id"
|
||||
has_many :inverse_followers, :through => :followers, :source => :user, :class_name => "JamRuby::User", :foreign_key => "follower_id"
|
||||
has_many :inverse_followers, :through => :followers, :class_name => "JamRuby::User", :foreign_key => "follower_id"
|
||||
|
||||
# user likers (a musician has likers and may have likes too; fans do not have likers)
|
||||
has_many :likers, :class_name => "JamRuby::UserLiker", :foreign_key => "user_id"
|
||||
has_many :inverse_likers, :through => :likers, :class_name => "JamRuby::User", :foreign_key => "liker_id"
|
||||
|
||||
# user followings
|
||||
has_many :followings, :class_name => "JamRuby::UserFollowing", :foreign_key => "follower_id"
|
||||
has_many :inverse_followings, :through => :followings, :source => :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
has_many :inverse_followings, :through => :followings, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
|
||||
# user likes (fans and musicians have likes)
|
||||
has_many :likes, :class_name => "JamRuby::UserLike", :foreign_key => "liker_id"
|
||||
has_many :inverse_likes, :through => :followings, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
|
||||
# band followings
|
||||
has_many :band_followings, :class_name => "JamRuby::BandFollower", :foreign_key => "follower_id"
|
||||
has_many :inverse_band_followings, :through => :band_followings, :class_name => "JamRuby::Band", :foreign_key => "band_id"
|
||||
|
||||
# band likes
|
||||
has_many :band_likes, :class_name => "JamRuby::BandLike", :foreign_key => "liker_id"
|
||||
has_many :inverse_band_likes, :through => :band_likes, :class_name => "JamRuby::Band", :foreign_key => "band_id"
|
||||
|
||||
# favorites
|
||||
has_many :favorites, :class_name => "JamRuby::UserFavorite", :foreign_key => "user_id"
|
||||
has_many :inverse_favorites, :through => :favorites, :source => :user, :class_name => "JamRuby::User"
|
||||
has_many :inverse_favorites, :through => :favorites, :class_name => "JamRuby::User"
|
||||
|
||||
# friends
|
||||
has_many :friendships, :class_name => "JamRuby::Friendship", :foreign_key => "user_id"
|
||||
|
|
@ -107,6 +119,10 @@ module JamRuby
|
|||
return self.friends.size
|
||||
end
|
||||
|
||||
def liker_count
|
||||
return 0
|
||||
end
|
||||
|
||||
def follower_count
|
||||
return self.followers.size
|
||||
end
|
||||
|
|
@ -114,15 +130,23 @@ module JamRuby
|
|||
def following_count
|
||||
return self.followings.size + self.band_followings.size
|
||||
end
|
||||
|
||||
def confirm_email!
|
||||
self.email_confirmed = true
|
||||
end
|
||||
|
||||
def favorite_count
|
||||
return self.favorites.size
|
||||
end
|
||||
|
||||
def recording_count
|
||||
return self.recordings.size
|
||||
end
|
||||
|
||||
def session_count
|
||||
return self.music_sessions.size
|
||||
end
|
||||
|
||||
def confirm_email!
|
||||
self.email_confirmed = true
|
||||
end
|
||||
|
||||
def to_s
|
||||
return email unless email.nil?
|
||||
|
||||
|
|
@ -247,8 +271,13 @@ module JamRuby
|
|||
follower.save
|
||||
end
|
||||
|
||||
def self.delete_user_following(user_id, follower_id)
|
||||
JamRuby::UserFollower.delete_all "(user_id = '#{user_id}' AND follower_id = '#{follower_id}')"
|
||||
def self.delete_following(user_id, band_id, follower_id)
|
||||
if !user_id.nil?
|
||||
JamRuby::UserFollower.delete_all "(user_id = '#{user_id}' AND follower_id = '#{follower_id}')"
|
||||
|
||||
elsif !band_id.nil?
|
||||
JamRuby::BandFollower.delete_all "(band_id = '#{band_id}' AND follower_id = '#{follower_id}')"
|
||||
end
|
||||
end
|
||||
|
||||
def self.create_band_following(band_id, follower_id)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
module JamRuby
|
||||
class UserLike < ActiveRecord::Base
|
||||
|
||||
self.table_name = "users_likers"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id", :inverse_of => :inverse_likes
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
module JamRuby
|
||||
class UserLiker < ActiveRecord::Base
|
||||
|
||||
self.table_name = "users_likers"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_id", :inverse_of => :inverse_likers
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue