Skip to content

Commit

Permalink
Rename 'id' issue tracker parameter to 'name'
Browse files Browse the repository at this point in the history
The 'id' was used for this parameter because it is the default for
resources in Rails, but looking at how it is being used, it is clearly a
name.
  • Loading branch information
eduardoj committed Jan 14, 2021
1 parent 7840ee1 commit 148a8ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/api/app/controllers/issue_trackers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def create

# GET /issue_trackers/<name>
def show
@issue_tracker = IssueTracker.find_by_name(params[:id])
render_error(status: 404, errorcode: 'not_found', message: "Unable to find issue tracker '#{params[:id]}'") && return unless @issue_tracker
@issue_tracker = IssueTracker.find_by_name(params[:name])
render_error(status: 404, errorcode: 'not_found', message: "Unable to find issue tracker '#{params[:name]}'") && return unless @issue_tracker

respond_to do |format|
format.xml { render xml: @issue_tracker.to_xml(IssueTracker::DEFAULT_RENDER_PARAMS) }
Expand All @@ -62,7 +62,7 @@ def update
attribs[:enable_fetch] = xml.xpath('enable-fetch[1]/text()').to_s unless xml.xpath('enable-fetch[1]/text()').empty?
attribs[:show_url] = xml.xpath('show-url[1]/text()').to_s unless xml.xpath('show-url[1]/text()').empty?

issue_tracker = IssueTracker.find_by_name(params[:id])
issue_tracker = IssueTracker.find_by_name(params[:name])
if issue_tracker
issue_tracker.update(attribs)
else
Expand All @@ -74,8 +74,8 @@ def update

# DELETE /issue_trackers/<name>
def destroy
@issue_tracker = IssueTracker.find_by_name(params[:id])
render_error(status: 404, errorcode: 'not_found', message: "Unable to find issue tracker '#{params[:id]}'") && return unless @issue_tracker
@issue_tracker = IssueTracker.find_by_name(params[:name])
render_error(status: 404, errorcode: 'not_found', message: "Unable to find issue tracker '#{params[:name]}'") && return unless @issue_tracker

@issue_tracker.destroy

Expand Down
5 changes: 2 additions & 3 deletions src/api/app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ class IssuesController < ApplicationController
before_action :require_admin, only: [:create, :update, :destroy]

def show
required_parameters :id, :issue_tracker_id
required_parameters :id, :issue_tracker_name

# NOTE: issue_tracker_id is here actually the name
issue = Issue.find_or_create_by_name_and_tracker(params[:id], params[:issue_tracker_id], params[:force_update])
issue = Issue.find_or_create_by_name_and_tracker(params[:id], params[:issue_tracker_name], params[:force_update])

render xml: issue.render_axml
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/config/routes/api_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
post 'trigger/webhook' => 'services/webhooks#create'

### /issue_trackers
resources :issue_trackers, only: [:index, :show, :create, :update, :destroy] do
resources :issues, only: [:show] # Nested route
resources :issue_trackers, only: [:index, :show, :create, :update, :destroy], param: :name do
resources :issues, only: [:show]
end

### /statistics
Expand Down

0 comments on commit 148a8ce

Please sign in to comment.