Module: Lesli::Interfaces::Controllers::Subscribers

Defined in:
app/controllers/lesli/interfaces/controllers/subscribers.rb

Instance Method Summary collapse

Instance Method Details

#createJson

Returns Json that contains wheter the creation of the subscriber was successful or not. If it is not successful, it returs an error message.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let data = {
    subscriber: {
        notification_type: "web",
        action: "ticket_closed"
    }
};
this.http.post(`127.0.0.1/help/tickets/${ticket_id}/subscribers`, data);

Returns:

  • (Json)

    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..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.full_messages.to_sentence)
    end
end

#destroyJson

Returns A response that contains wheter the subscriber was deleted or not. If it is not successful, it returns an error message.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let subscriber_id = 22;
this.http.delete(`127.0.0.1/help/tickets/${ticket_id}/subscribers/${subscriber_id}`);

Returns:

  • (Json)

    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.full_messages.to_sentence)
    end
end

#indexJson

Returns Json that contains a list of all subscribers related to a cloud_object.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
this.http.get(`127.0.0.1/help/tickets/${ticket_id}/subscribers`);

Returns:

  • (Json)

    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..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

#updateJson

Returns Json that contains wheter the update of the subscriber was successful or not. If it is not successful, it returs an error message.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let subscriber_id = 22;
data = {
    subscriber: {
        notification_type: "email"
    }
};
this.http.patch(`127.0.0.1/help/tickets/${ticket_id}/subscribers/${subscriber_id}`, data);

Returns:

  • (Json)

    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.full_messages.to_sentence)
    end
end