Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.