Skip to content

Commit

Permalink
Merge pull request #9 from hsong-rh/add_relations_in_swagger
Browse files Browse the repository at this point in the history
Add relations into swagger file
  • Loading branch information
gmcculloug authored Nov 5, 2018
2 parents 3afcf8a + 1556e42 commit 8214aab
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 140 deletions.
44 changes: 2 additions & 42 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
=end
class AdminsController < ApplicationController

def add_action
stage = Stage.find(params[:stage_id])
action = stage.actions.create!(action_params)

json_response(action, :created)
end
include UserOperationsMixin
include ApproverOperationsMixin

def add_group
group = Group.create!(group_params)
Expand All @@ -39,18 +34,6 @@ def add_workflow
json_response(workflow, :created)
end

def fetch_action_by_id
action = Action.find(params[:id])

json_response(action)
end

def fetch_actions
actions = Action.all

json_response(actions)
end

def fetch_group_by_id
group = Group.find(params[:id])

Expand All @@ -69,12 +52,6 @@ def fetch_requests
json_response(reqs)
end

def fetch_stage_by_id
stage = Stage.find(params[:id])

json_response(stage)
end

def fetch_stages
stages = Stage.all

Expand Down Expand Up @@ -114,12 +91,6 @@ def fetch_workflows
json_response(workflows)
end

def remove_action
Action.find(params[:id]).destroy

head :no_content
end

def remove_group
Group.find(params[:id]).destroy
head :no_content
Expand All @@ -145,12 +116,6 @@ def remove_workflow
head :no_content
end

def update_action
Action.find(params[:id]).update(action_params)

head :no_content
end

def update_group
Group.find(params[:id]).update(group_params)
head :no_content
Expand All @@ -161,11 +126,6 @@ def update_request
head :no_content
end

def update_stage
StageUpdateService.new(params[:id]).update(stage_params)
head :no_content
end

def update_template
Template.find(params[:id]).update(template_params)
head :no_content
Expand Down
42 changes: 1 addition & 41 deletions app/controllers/approvers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,6 @@
=end
class ApproversController < ApplicationController
include ApproverOperationsMixin

def add_action
# Your code here

render json: {"message" => "yes, it worked"}
end

def fetch_action_by_id
# Your code here

render json: {"message" => "yes, it worked"}
end

def fetch_actions
# Your code here

render json: {"message" => "yes, it worked"}
end

def fetch_stage_by_id
# Your code here

render json: {"message" => "yes, it worked"}
end

def remove_action
# Your code here

render json: {"message" => "yes, it worked"}
end

def update_action
# Your code here

render json: {"message" => "yes, it worked"}
end

def update_stage
# Your code here

render json: {"message" => "yes, it worked"}
end
end
46 changes: 46 additions & 0 deletions app/controllers/mixins/approver_operations_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module ApproverOperationsMixin
extend ActiveSupport::Concern

def add_action
stage = Stage.find(params[:stage_id])
action = stage.actions.create!(action_params)

json_response(action, :created)
end

def fetch_action_by_id
action = Action.find(params[:id])

json_response(action)
end

def fetch_actions
actions = Action.all

json_response(actions)
end

def fetch_stage_by_id
stage = Stage.find(params[:id])

json_response(stage)
end

def remove_action
Action.find(params[:id]).destroy

head :no_content
end

def update_action
Action.find(params[:id]).update(action_params)

head :no_content
end

def update_stage
StageUpdateService.new(params[:id]).update(stage_params)
head :no_content
end

end
26 changes: 26 additions & 0 deletions app/controllers/mixins/user_operations_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module UserOperationsMixin
extend ActiveSupport::Concern

def add_request
req = RequestCreateService.new(params[:workflow_id]).create(request_params)
json_response(req, :created)
end

def fetch_request_by_id
req = Request.find(params[:id])
json_response(req)
end

def fetch_request_stages
req = Request.find(params[:request_id])

json_response(req.stages)
end

private

def request_params
params.permit(:name, :decision, :state, :requester, :content)
end

end
23 changes: 1 addition & 22 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,5 @@
=end
class UsersController < ApplicationController

def add_request
req = RequestCreateService.new(params[:workflow_id]).create(request_params)
json_response(req, :created)
end

def fetch_request_by_id
req = Request.find(params[:id])
json_response(req)
end

def fetch_request_stages
req = Request.find(params[:request_id])

json_response(req.stages)
end

private

def request_params
params.permit(:name, :decision, :state, :requester, :content)
end
include UserOperationsMixin
end
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ class Application < Rails::Application
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true

config.autoload_paths << Rails.root.join("app", "controllers", "mixins").to_s
end
end
Loading

0 comments on commit 8214aab

Please sign in to comment.