* VRFS-31; merging from master
This commit is contained in:
commit
be39434e1c
|
|
@ -12,13 +12,15 @@ require "jam_ruby/version"
|
|||
require "jam_ruby/message_factory"
|
||||
require "jam_ruby/models/genre"
|
||||
require "jam_ruby/models/user"
|
||||
require "jam_ruby/models/musician"
|
||||
require "jam_ruby/models/band"
|
||||
require "jam_ruby/models/connection"
|
||||
require "jam_ruby/models/friendship"
|
||||
require "jam_ruby/models/music_session"
|
||||
require "jam_ruby/models/invitation"
|
||||
require "jam_ruby/models/friend_request"
|
||||
require "jam_ruby/models/instrument"
|
||||
require "jam_ruby/models/musician_instrument"
|
||||
require "jam_ruby/models/band_musician"
|
||||
|
||||
include Jampb
|
||||
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@
|
|||
end
|
||||
|
||||
# create a user-joined session message
|
||||
def user_joined_music_session(user_id, username)
|
||||
joined = Jampb::UserJoinedMusicSession.new(:user_id => user_id, :username => username)
|
||||
def user_joined_music_session(session_id, user_id, username)
|
||||
joined = Jampb::UserJoinedMusicSession.new(:session_id => session_id, :user_id => user_id, :username => username)
|
||||
return Jampb::ClientMessage.new(:type => ClientMessage::Type::USER_JOINED_MUSIC_SESSION, :route_to => CLIENT_TARGET, :user_joined_music_session => joined)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,24 @@
|
|||
module JamRuby
|
||||
class Band < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
self.primary_key = 'id'
|
||||
|
||||
has_and_belongs_to_many :musicians, :class_name => "JamRuby::Musician"
|
||||
# musicians
|
||||
has_many :band_musicians
|
||||
has_many :users, :through => :band_musicians, :class_name => "JamRuby::User"
|
||||
|
||||
# genres
|
||||
has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "bands_genres"
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
module JamRuby
|
||||
class BandMusician < ActiveRecord::Base
|
||||
|
||||
self.table_name = "bands_musicians"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :band
|
||||
|
||||
# name, genres, photo_url, and logo_url are needed here for the RABL file
|
||||
def name
|
||||
@name = self.band.name
|
||||
end
|
||||
|
||||
def genres
|
||||
@genres = self.band.genres
|
||||
end
|
||||
|
||||
def photo_url
|
||||
@photo_url = self.band.photo_url
|
||||
end
|
||||
|
||||
def logo_url
|
||||
@logo_url = self.band.logo_url
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -9,5 +9,9 @@ module JamRuby
|
|||
validates :user_id, :presence => true
|
||||
validates :friend_id, :presence => true
|
||||
|
||||
def to_s
|
||||
return "#{self.user.to_s}:#{self.friend.to_s}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
module JamRuby
|
||||
class Genre < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
self.primary_key = 'id'
|
||||
|
||||
has_and_belongs_to_many :musicians, :class_name => "JamRuby::Musician"
|
||||
# bands
|
||||
has_and_belongs_to_many :bands, :class_name => "JamRuby::Band", :join_table => "bands_genres"
|
||||
|
||||
# music sessions
|
||||
has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions"
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
module JamRuby
|
||||
class Instrument < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
# users
|
||||
has_many :musician_instruments
|
||||
has_many :users, :through => :musician_instruments, :class_name => "JamRuby::User"
|
||||
|
||||
# music sessions
|
||||
has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
module JamRuby
|
||||
class Musician < JamRuby::User
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
has_and_belongs_to_many :bands, :class_name => "JamRuby::Band"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
module JamRuby
|
||||
class MusicianInstrument < ActiveRecord::Base
|
||||
|
||||
self.table_name = "musicians_instruments"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :instrument
|
||||
|
||||
def description
|
||||
@description = self.instrument.description
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -2,23 +2,32 @@ module JamRuby
|
|||
class User < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :password, :password_confirmation
|
||||
attr_accessor :updating_password, :online
|
||||
attr_accessor :updating_password
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
# re-visit later (used for multiple table inheritance w/ Musician model)
|
||||
# belongs_to :biz, :polymorphic => true
|
||||
|
||||
# connections (websocket-gateway)
|
||||
has_many :connections, :class_name => "JamRuby::Connection"
|
||||
|
||||
# friend requests
|
||||
has_many :friend_requests, :class_name => "JamRuby::FriendRequest"
|
||||
|
||||
# instruments
|
||||
has_many :musician_instruments
|
||||
has_many :instruments, :through => :musician_instruments, :class_name => "JamRuby::Instrument"
|
||||
|
||||
# bands
|
||||
has_many :band_musicians
|
||||
has_many :bands, :through => :band_musicians, :class_name => "JamRuby::Band"
|
||||
|
||||
# friends
|
||||
has_many :friendships, :class_name => "JamRuby::Friendship", :foreign_key => "user_id"
|
||||
has_many :friends, :through => :friendships, :class_name => "JamRuby::User"
|
||||
has_many :inverse_friendships, :class_name => "JamRuby::Friendship", :foreign_key => "friend_id"
|
||||
has_many :inverse_friends, :through => :inverse_friendships, :source => :user, :class_name => "JamRuby::User"
|
||||
has_many :created_music_sessions, :foreign_key => "user_id", :inverse_of => :user, :class_name => "JamRuby::MusicSession" # sessions *created* by the user
|
||||
has_many :music_sessions, :through => :connections, :class_name => "JamRuby::MusicSession"
|
||||
|
||||
has_many :received_invitations, :foreign_key => "receiver_id", :inverse_of => :receiver, :class_name => "JamRuby::Invitation"
|
||||
has_many :sent_invitations, :foreign_key => "sender_id", :inverse_of => :sender, :class_name => "JamRuby::Invitation"
|
||||
|
||||
|
|
@ -42,6 +51,11 @@ module JamRuby
|
|||
return @online
|
||||
end
|
||||
|
||||
def photo_url
|
||||
# TODO: move image path to config
|
||||
@photo_url = "http://www.jamkazam.com/images/users/photos/#{self.id}.gif";
|
||||
end
|
||||
|
||||
def should_validate_password?
|
||||
updating_password || new_record?
|
||||
end
|
||||
|
|
@ -56,6 +70,24 @@ module JamRuby
|
|||
return id
|
||||
end
|
||||
|
||||
def self.save(params)
|
||||
if params[:id].nil?
|
||||
user = User.new()
|
||||
else
|
||||
user = User.find(params[:id])
|
||||
end
|
||||
|
||||
@user = User.find(params[:id])
|
||||
@user.email = params[:email]
|
||||
@user.musician = params[:musician]
|
||||
if @user.musician
|
||||
@user.instruments = params[:instruments]
|
||||
@user.bands = params[:bands]
|
||||
end
|
||||
@user.save
|
||||
return user
|
||||
end
|
||||
|
||||
private
|
||||
def create_remember_token
|
||||
self.remember_token = SecureRandom.urlsafe_base64
|
||||
|
|
|
|||
Loading…
Reference in New Issue