Module: Lesli::Interfaces::Controllers::Subscribers
- Defined in:
- app/controllers/lesli/interfaces/controllers/subscribers.rb
Instance Method Summary collapse
-
#create ⇒ Json
Json that contains wheter the creation of the subscriber was successful or not.
-
#destroy ⇒ Json
A response that contains wheter the subscriber was deleted or not.
-
#index ⇒ Json
Json that contains a list of all subscribers related to a cloud_object.
-
#update ⇒ Json
Json that contains wheter the update of the subscriber was successful or not.
Instance Method Details
#create ⇒ Json
Returns Json that contains wheter the creation of the subscriber was successful or not. If it is not successful, it returs an error message.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/lesli/interfaces/controllers/subscribers.rb', line 79 def create subscriber_model = subscriber_model() # If there is a custom subscriber model, it must be returned in this method cloud_object_model = subscriber_model.cloud_object_model target_user = current_user.account.users.find_by(id: params[:users_id]) if params[:users_id] target_user = current_user unless target_user set_cloud_object new_subscriber_params = subscriber_params.merge( user_creator: target_user, cloud_object: @cloud_object ) cloud_object_subscriber = subscriber_model.new(new_subscriber_params) if cloud_object_subscriber.save respond_with_successful(cloud_object_subscriber) else respond_with_error(cloud_object_subscriber.errors..to_sentence) end end |
#destroy ⇒ Json
Returns A response that contains wheter the subscriber was deleted or not. If it is not successful, it returns an error message.
134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/lesli/interfaces/controllers/subscribers.rb', line 134 def destroy set_subscriber return respond_with_not_found unless @subscriber if @subscriber.destroy respond_with_successful else respond_with_error(@subscriber.errors..to_sentence) end end |
#index ⇒ Json
Returns Json that contains a list of all subscribers related to a cloud_object.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/lesli/interfaces/controllers/subscribers.rb', line 45 def index subscriber_model = subscriber_model() # If there is a custom subscriber model, it must be returned in this method cloud_object_model = subscriber_model.cloud_object_model @cloud_object = cloud_object_model.find_by(id: params["#{cloud_object_model.name.demodulize.underscore}_id".to_sym]) return respond_with_not_found unless @cloud_object target_user = current_user.account.users.find_by(id: params[:users_id]) if params[:users_id] target_user = current_user unless target_user actions = subscriber_model.subscription_actions( @cloud_object, target_user ) respond_with_successful(actions) end |
#update ⇒ Json
Returns Json that contains wheter the update of the subscriber was successful or not. If it is not successful, it returs an error message.
115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/lesli/interfaces/controllers/subscribers.rb', line 115 def update set_subscriber return respond_with_not_found unless @subscriber if @subscriber.update(subscriber_params) respond_with_successful else respond_with_error(@subscriber.errors..to_sentence) end end |