Created
October 31, 2013 17:21
-
-
Save reedlaw/7253542 to your computer and use it in GitHub Desktop.
CRUD action interactors
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 LoadLocation < Interactor | |
def call | |
@response.location = location.attributes | |
@response | |
end | |
def location | |
LocationRepository.joins(:manager) | |
.select("*, user_repository.name AS manager_name") | |
.where(account_repository_id: @request.current_account_id) | |
.find(@request.params[:id]) | |
end | |
end | |
class LoadLocations < Interactor | |
def call | |
@response.locations = locations | |
@response | |
end | |
def locations | |
LocationRepository.joins(:manager) | |
.select("*, user_repository.name AS manager_name") | |
.where(account_repository_id: @request.current_account_id) | |
.map(&:attributes) | |
end | |
end | |
class SaveLocation < Interactor | |
def call | |
location = Location.new(@request.object_attributes) | |
if location.valid? | |
repo = save_repository(LocationRepository) | |
@response.location = repo.attributes | |
else | |
@response.location = @request.object_attributes | |
@response.location.errors = location.errors | |
end | |
@response | |
end | |
end | |
class DeleteLocation < Interactor | |
def call | |
@response = delete(LocationRepository) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment