Created
April 28, 2015 13:57
-
-
Save quangpham/a36adb01985709fc1d9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::Mobile::V1::FacilitiesController < Api::Mobile::V1::ApplicationApiController | |
# include ApplicationHelper | |
acts_as_token_authentication_handler_for User | |
before_action :check_user_house_access | |
before_action :set_facility, only: [:show] | |
def index | |
return render json: Facility.where(house_id: params[:house_id]) | |
end | |
def show | |
house = @facility.house | |
_facility = @facility.as_json | |
_facility[:firebase_base_url] = house.firebase_base_url | |
render json: _facility | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_facility | |
unless @facility = Facility.find_by(id: params[:id]) | |
return render status: 404, json: {error: "facility_not_found"} | |
end | |
end | |
def check_user_house_access | |
return render status: 400, json: {error: "house_id_missing"} unless params[:house_id] | |
if user_house_r = UserHouseR.find_by(user_id: current_user.id, house_id: params[:house_id]) | |
return render status: 403, json: {error: "membership_not_yet_confirmed"} unless user_house_r.is_member | |
else | |
return render status: 403, json: {error: "use_is_not_member_of_this_house"} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment