Created
May 12, 2014 15:50
-
-
Save fuadsaud/86cfd5236c0f77a4cd1c to your computer and use it in GitHub Desktop.
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
class TeamsController | |
class Index | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
end | |
def model | |
repository.sorted_by_name | |
end | |
end | |
class Show | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
end | |
def model | |
repository.find(params[:id]) | |
end | |
end | |
class New | |
include RoomReservation::Action | |
def call(params) | |
end | |
def model | |
TeamsFormFactory.create | |
end | |
end | |
class Create | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
persist! | |
redirect_to_index | |
end | |
def form_invalid | |
throw 422 | |
end | |
def persist! | |
repository.persist(team) | |
end | |
def model | |
TeamsFormFactory.create | |
end | |
def flash | |
{ notice: 'The team was created!' } | |
end | |
private | |
def team | |
model.populate(team_params, self) | |
end | |
def team_params | |
params.fetch(:team) | |
end | |
def redirect_to_index | |
redirect_to index_path | |
end | |
def index_path | |
router.path(:teams) | |
end | |
end | |
class Edit | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
end | |
def model | |
TeamsFormFactory.update(team) | |
end | |
def team | |
@repository.find(params[:id]) | |
end | |
end | |
class Update | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
persist! | |
redirect_to_index | |
end | |
def form_invalid | |
throw 422 | |
end | |
def model | |
TeamsFormFactory.update(team) | |
end | |
def flash | |
{ notice: 'The team was updated!' } | |
end | |
private | |
def persist! | |
repository.persist(team) | |
end | |
def entity | |
repository.find(params[:id]) | |
end | |
def team | |
model.populate(team_params, self) | |
end | |
def team_params | |
params.fetch(:team) | |
end | |
def index_path | |
router.path(:teams) | |
end | |
def redirect_to_index | |
redirect_to index_path | |
end | |
end | |
class Destroy | |
include RoomReservation::Action | |
def initialize(repository: TeamRepository) | |
@repository = repository | |
end | |
def call(params) | |
delete! | |
redirect_to_index | |
end | |
def model | |
repository.find(params[:id]) | |
end | |
def flash | |
{ notice: 'The team was deleted!' } | |
end | |
private | |
def delete! | |
repository.delete(model) | |
end | |
def redirect_to_index | |
redirect_to index_path | |
end | |
def index_path | |
router.path(:teams) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment