docbrown/app/controllers/api/v0/reactions_controller.rb
Andy Zhao deb63ab643 Add Save Articles Page to Onboarding (#182)
* Add MVP of onboarding articles

* Lint and fix unfollow all button bug

* Update onboarding tests

* Fix typo and adjust when saveAll request gets sent

* Set default to always save all articles

* Fix when request is sent for follows/saves

* Check for article length when for initial request

* Add a loading indicator for follows page

* Prevent multiple follow/save requests

* Update tests

* Add some hover and click effects

* Adjust onboarding test and suggested articles
2018-04-05 11:41:28 -07:00

43 lines
1.2 KiB
Ruby

module Api
module V0
class ReactionsController < ApplicationController
skip_before_action :verify_authenticity_token
def create
@user = valid_user
unless @user
render json: { message: "invalid_user" }, :status => 422
return
end
Rails.cache.delete "count_for_reactable-#{params[:reactable_type]}-#{params[:reactable_id]}"
@reaction = Reaction.create(
user_id: @user.id,
reactable_id: params[:reactable_id],
reactable_type: params[:reactable_type],
category: params[:category] || "like",
)
render json: { reaction: @reaction.to_json }
end
def onboarding
verify_authenticity_token
reactable_ids = JSON.parse(params[:articles]).map { |article| article["id"] }
reactable_ids.each do |article_id|
Reaction.delay.create(
user_id: current_user.id,
reactable_id: article_id,
reactable_type: "Article",
category: "readinglist",
)
end
end
private
def valid_user
user = User.find_by_secret(params[:key])
user = nil if !user.has_role?(:super_admin)
user
end
end
end
end