Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer
Created December 1, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plainprogrammer/f10e85494f1eae6d39993336c4dd18e7 to your computer and use it in GitHub Desktop.
Save plainprogrammer/f10e85494f1eae6d39993336c4dd18e7 to your computer and use it in GitHub Desktop.
Applying Clean Architecture: Rails Controllers
module Api
class BusinessProfilesController < ApplicationController
before_action :validate_accept_header
before_action :validate_content_type_header
before_action :validate_account_id
def show
load_business_profile
render jsonapi: business_profile, status: show_status
end
def create
update_business_profile
render jsonapi: business_profile, status: update_status
end
def update
update_business_profile
render jsonapi: business_profile, status: update_status
end
private
def repository
Repositories::BusinessProfiles.new
end
def load_business_profile
@business_profile = repository.find params[:id]
end
def update_business_profile
updater = Nav::UpdateBusinessProfile.new repository: repository
@business_profile = updater.with id: params[:id] || update_params[:id],
attributes: update_params[:attributes].to_hash
end
def business_profile
Presenters::BusinessProfile.present @business_profile
end
# Private Methods Ommited
# validate_accept_header
# validate_content_type_header
# validate_account_id
# show_status
# update_status
# update_params
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment