API: extracted helper method to validate required parameters, code clean up
Added a helper method to check if required parameters are given in an API call. Can be used to return a `400 Bad Request` return code if a required attribute is missing. Code clean up and fixed tests.
This commit is contained in:
parent
43d7596030
commit
7499f65014
10 changed files with 35 additions and 42 deletions
|
@ -37,7 +37,7 @@ module Gitlab
|
|||
# Example Request:
|
||||
# POST /projects/:id/notes
|
||||
post ":id/notes" do
|
||||
bad_request!(:body) unless params[:body].present?
|
||||
required_attributes! [:body]
|
||||
|
||||
@note = user_project.notes.new(note: params[:body])
|
||||
@note.author = current_user
|
||||
|
@ -93,8 +93,7 @@ module Gitlab
|
|||
# POST /projects/:id/issues/:noteable_id/notes
|
||||
# POST /projects/:id/snippets/:noteable_id/notes
|
||||
post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do
|
||||
bad_request!(:"#{noteable_id_str}") unless params[:"#{noteable_id_str}"].present?
|
||||
bad_request!(:body) unless params[:body].present?
|
||||
required_attributes! [:"#{noteable_id_str}"]
|
||||
|
||||
@noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"])
|
||||
@note = @noteable.notes.new(note: params[:body])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue