-
-
Save plainprogrammer/f10e85494f1eae6d39993336c4dd18e7 to your computer and use it in GitHub Desktop.
Applying Clean Architecture: Rails Controllers
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
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