Last active
August 29, 2015 13:56
-
-
Save jsuchal/9024136 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DonationsController # < ActionController::Base | |
| def create | |
| donation_service.add_donation(current_user, params, bus.on( | |
| donation_created: ->(donation) { send_user_to_payment_gateway(donation) }, | |
| donation_invalid: ->(donation) { render donation.errors, status: :bad_request } | |
| )) | |
| end | |
| private | |
| def donation_service | |
| DonationService.new # inject dependencies | |
| end | |
| def send_user_to_payment_gateway(donation) | |
| #... | |
| end | |
| end |
This file contains hidden or 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 DonationsController # < ActionController::Base | |
| def create | |
| build_service.create_donation(current_user, params, bus.attach(self)) | |
| end | |
| def donation_created(donation) | |
| send_user_to_payment_gateway(donation) | |
| end | |
| def donation_invalid(donation) | |
| donation_invalid: ->(donation) { render donation.errors, status: :bad_request } | |
| end | |
| private | |
| def send_user_to_payment_gateway(donation) | |
| #... | |
| end | |
| protected | |
| def build_service | |
| DonationService.new # inject dependencies | |
| end | |
| end |
This file contains hidden or 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 DonationsController # < ActionController::Base | |
| include Bus::ServiceController.new(service: DonationService, event_prefix: :donation, actions: :create) | |
| def donation_created(donation) | |
| send_user_to_payment_gateway(donation) | |
| end | |
| def donation_invalid(donation) | |
| render donation.errors, status: :bad_request | |
| end | |
| private | |
| def send_user_to_payment_gateway(donation) | |
| #... | |
| end | |
| protected | |
| def service_parameters | |
| [current_user, params] | |
| end | |
| end |
This file contains hidden or 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 DonationsController # < ActionController::Base | |
| include Bus::ServiceController.new(actions: :create) # implicit from controller name | |
| def donation_created(donation) | |
| send_user_to_payment_gateway(donation) | |
| end | |
| def donation_invalid(donation) | |
| render donation.errors, status: :bad_request | |
| end | |
| private | |
| def send_user_to_payment_gateway(donation) | |
| #... | |
| end | |
| protected | |
| def service_parameters | |
| [current_user, params] | |
| end | |
| end |
This file contains hidden or 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 DonationsController # < ActionController::Base | |
| service_actions :create | |
| def donation_created(donation) | |
| send_user_to_payment_gateway(donation) | |
| end | |
| def donation_invalid(donation) | |
| render donation.errors, status: :bad_request | |
| end | |
| private | |
| def send_user_to_payment_gateway(donation) | |
| #... | |
| end | |
| protected | |
| def service_parameters | |
| [current_user, params] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment