Commit 626e79b6 authored by Robert Schilling's avatar Robert Schilling

Split V3 entities into a separate file

parent 5985b557
...@@ -694,19 +694,5 @@ module API ...@@ -694,19 +694,5 @@ module API
expose :id, :message, :starts_at, :ends_at, :color, :font expose :id, :message, :starts_at, :ends_at, :color, :font
expose :active?, as: :active expose :active?, as: :active
end end
# Entities for the deprecated V3 API
class ProjectSnippetV3 < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
expose :updated_at, :created_at
# TODO (rspeicher): Deprecated; remove in 9.0
expose(:expires_at) { |snippet| nil }
expose :web_url do |snippet, options|
Gitlab::UrlBuilder.build(snippet)
end
end
end end
end end
module API
module V3
module Entities
class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: ::API::Entities::UserBasic
expose :updated_at, :created_at
expose(:expires_at) { |snippet| nil }
expose :web_url do |snippet, options|
Gitlab::UrlBuilder.build(snippet)
end
end
end
end
end
...@@ -50,7 +50,7 @@ module API ...@@ -50,7 +50,7 @@ module API
resource :issues do resource :issues do
desc "Get currently authenticated user's issues" do desc "Get currently authenticated user's issues" do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
optional :state, type: String, values: %w[opened closed all], default: 'all', optional :state, type: String, values: %w[opened closed all], default: 'all',
...@@ -60,7 +60,7 @@ module API ...@@ -60,7 +60,7 @@ module API
get do get do
issues = find_issues(scope: 'authored') issues = find_issues(scope: 'authored')
present paginate(issues), with: Entities::Issue, current_user: current_user present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
end end
end end
...@@ -69,7 +69,7 @@ module API ...@@ -69,7 +69,7 @@ module API
end end
resource :groups do resource :groups do
desc 'Get a list of group issues' do desc 'Get a list of group issues' do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
optional :state, type: String, values: %w[opened closed all], default: 'opened', optional :state, type: String, values: %w[opened closed all], default: 'opened',
...@@ -81,7 +81,7 @@ module API ...@@ -81,7 +81,7 @@ module API
issues = find_issues(group_id: group.id, state: params[:state] || 'opened', match_all_labels: true) issues = find_issues(group_id: group.id, state: params[:state] || 'opened', match_all_labels: true)
present paginate(issues), with: Entities::Issue, current_user: current_user present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
end end
end end
...@@ -93,7 +93,7 @@ module API ...@@ -93,7 +93,7 @@ module API
desc 'Get a list of project issues' do desc 'Get a list of project issues' do
detail 'iid filter is deprecated have been removed on V4' detail 'iid filter is deprecated have been removed on V4'
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
optional :state, type: String, values: %w[opened closed all], default: 'all', optional :state, type: String, values: %w[opened closed all], default: 'all',
...@@ -106,22 +106,22 @@ module API ...@@ -106,22 +106,22 @@ module API
issues = find_issues(project_id: project.id) issues = find_issues(project_id: project.id)
present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project present paginate(issues), with: ::API::Entities::Issue, current_user: current_user, project: user_project
end end
desc 'Get a single project issue' do desc 'Get a single project issue' do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue' requires :issue_id, type: Integer, desc: 'The ID of a project issue'
end end
get ":id/issues/:issue_id" do get ":id/issues/:issue_id" do
issue = find_project_issue(params[:issue_id]) issue = find_project_issue(params[:issue_id])
present issue, with: Entities::Issue, current_user: current_user, project: user_project present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
end end
desc 'Create a new project issue' do desc 'Create a new project issue' do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
requires :title, type: String, desc: 'The title of an issue' requires :title, type: String, desc: 'The title of an issue'
...@@ -153,14 +153,14 @@ module API ...@@ -153,14 +153,14 @@ module API
end end
if issue.valid? if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
else else
render_validation_error!(issue) render_validation_error!(issue)
end end
end end
desc 'Update an existing issue' do desc 'Update an existing issue' do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue' requires :issue_id, type: Integer, desc: 'The ID of a project issue'
...@@ -186,14 +186,14 @@ module API ...@@ -186,14 +186,14 @@ module API
declared_params(include_missing: false)).execute(issue) declared_params(include_missing: false)).execute(issue)
if issue.valid? if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
else else
render_validation_error!(issue) render_validation_error!(issue)
end end
end end
desc 'Move an existing issue' do desc 'Move an existing issue' do
success Entities::Issue success ::API::Entities::Issue
end end
params do params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue' requires :issue_id, type: Integer, desc: 'The ID of a project issue'
...@@ -208,7 +208,7 @@ module API ...@@ -208,7 +208,7 @@ module API
begin begin
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project) issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
present issue, with: Entities::Issue, current_user: current_user, project: user_project present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
rescue ::Issues::MoveService::MoveError => error rescue ::Issues::MoveService::MoveError => error
render_api_error!(error.message, 400) render_api_error!(error.message, 400)
end end
......
...@@ -39,7 +39,7 @@ module API ...@@ -39,7 +39,7 @@ module API
desc 'List merge requests' do desc 'List merge requests' do
detail 'iid filter is deprecated have been removed on V4' detail 'iid filter is deprecated have been removed on V4'
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
params do params do
optional :state, type: String, values: %w[opened closed merged all], default: 'all', optional :state, type: String, values: %w[opened closed merged all], default: 'all',
...@@ -66,11 +66,11 @@ module API ...@@ -66,11 +66,11 @@ module API
end end
merge_requests = merge_requests.reorder(params[:order_by] => params[:sort]) merge_requests = merge_requests.reorder(params[:order_by] => params[:sort])
present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user, project: user_project present paginate(merge_requests), with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Create a merge request' do desc 'Create a merge request' do
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
params do params do
requires :title, type: String, desc: 'The title of the merge request' requires :title, type: String, desc: 'The title of the merge request'
...@@ -89,7 +89,7 @@ module API ...@@ -89,7 +89,7 @@ module API
merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute
if merge_request.valid? if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
else else
handle_merge_request_errors! merge_request.errors handle_merge_request_errors! merge_request.errors
end end
...@@ -114,34 +114,34 @@ module API ...@@ -114,34 +114,34 @@ module API
if status == :deprecated if status == :deprecated
detail DEPRECATION_MESSAGE detail DEPRECATION_MESSAGE
end end
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
get path do get path do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Get the commits of a merge request' do desc 'Get the commits of a merge request' do
success Entities::RepoCommit success ::API::Entities::RepoCommit
end end
get "#{path}/commits" do get "#{path}/commits" do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request.commits, with: Entities::RepoCommit present merge_request.commits, with: ::API::Entities::RepoCommit
end end
desc 'Show the merge request changes' do desc 'Show the merge request changes' do
success Entities::MergeRequestChanges success ::API::Entities::MergeRequestChanges
end end
get "#{path}/changes" do get "#{path}/changes" do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
present merge_request, with: Entities::MergeRequestChanges, current_user: current_user present merge_request, with: ::API::Entities::MergeRequestChanges, current_user: current_user
end end
desc 'Update a merge request' do desc 'Update a merge request' do
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
params do params do
optional :title, type: String, allow_blank: false, desc: 'The title of the merge request' optional :title, type: String, allow_blank: false, desc: 'The title of the merge request'
...@@ -162,14 +162,14 @@ module API ...@@ -162,14 +162,14 @@ module API
merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request) merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request)
if merge_request.valid? if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
else else
handle_merge_request_errors! merge_request.errors handle_merge_request_errors! merge_request.errors
end end
end end
desc 'Merge a merge request' do desc 'Merge a merge request' do
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
params do params do
optional :merge_commit_message, type: String, desc: 'Custom merge commit message' optional :merge_commit_message, type: String, desc: 'Custom merge commit message'
...@@ -209,11 +209,11 @@ module API ...@@ -209,11 +209,11 @@ module API
.execute(merge_request) .execute(merge_request)
end end
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: ::API::Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do
success Entities::MergeRequest success ::API::Entities::MergeRequest
end end
post "#{path}/cancel_merge_when_build_succeeds" do post "#{path}/cancel_merge_when_build_succeeds" do
merge_request = find_project_merge_request(params[:merge_request_id]) merge_request = find_project_merge_request(params[:merge_request_id])
...@@ -227,19 +227,19 @@ module API ...@@ -227,19 +227,19 @@ module API
desc 'Get the comments of a merge request' do desc 'Get the comments of a merge request' do
detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4' detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
success Entities::MRNote success ::API::Entities::MRNote
end end
params do params do
use :pagination use :pagination
end end
get "#{path}/comments" do get "#{path}/comments" do
merge_request = find_merge_request_with_access(params[:merge_request_id]) merge_request = find_merge_request_with_access(params[:merge_request_id])
present paginate(merge_request.notes.fresh), with: Entities::MRNote present paginate(merge_request.notes.fresh), with: ::API::Entities::MRNote
end end
desc 'Post a comment to a merge request' do desc 'Post a comment to a merge request' do
detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4' detail 'Duplicate. DEPRECATED and HAS BEEN REMOVED in V4'
success Entities::MRNote success ::API::Entities::MRNote
end end
params do params do
requires :note, type: String, desc: 'The text of the comment' requires :note, type: String, desc: 'The text of the comment'
...@@ -256,14 +256,14 @@ module API ...@@ -256,14 +256,14 @@ module API
note = ::Notes::CreateService.new(user_project, current_user, opts).execute note = ::Notes::CreateService.new(user_project, current_user, opts).execute
if note.save if note.save
present note, with: Entities::MRNote present note, with: ::API::Entities::MRNote
else else
render_api_error!("Failed to save note #{note.errors.messages}", 400) render_api_error!("Failed to save note #{note.errors.messages}", 400)
end end
end end
desc 'List issues that will be closed on merge' do desc 'List issues that will be closed on merge' do
success Entities::MRNote success ::API::Entities::MRNote
end end
params do params do
use :pagination use :pagination
......
...@@ -24,28 +24,28 @@ module API ...@@ -24,28 +24,28 @@ module API
end end
desc 'Get all project snippets' do desc 'Get all project snippets' do
success Entities::ProjectSnippetV3 success ::API::V3::Entities::ProjectSnippet
end end
params do params do
use :pagination use :pagination
end end
get ":id/snippets" do get ":id/snippets" do
present paginate(snippets_for_current_user), with: Entities::ProjectSnippetV3 present paginate(snippets_for_current_user), with: ::API::V3::Entities::ProjectSnippet
end end
desc 'Get a single project snippet' do desc 'Get a single project snippet' do
success Entities::ProjectSnippetV3 success ::API::V3::Entities::ProjectSnippet
end end
params do params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
end end
get ":id/snippets/:snippet_id" do get ":id/snippets/:snippet_id" do
snippet = snippets_for_current_user.find(params[:snippet_id]) snippet = snippets_for_current_user.find(params[:snippet_id])
present snippet, with: Entities::ProjectSnippetV3 present snippet, with: ::API::V3::Entities::ProjectSnippet
end end
desc 'Create a new project snippet' do desc 'Create a new project snippet' do
success Entities::ProjectSnippetV3 success ::API::V3::Entities::ProjectSnippet
end end
params do params do
requires :title, type: String, desc: 'The title of the snippet' requires :title, type: String, desc: 'The title of the snippet'
...@@ -65,14 +65,14 @@ module API ...@@ -65,14 +65,14 @@ module API
snippet = CreateSnippetService.new(user_project, current_user, snippet_params).execute snippet = CreateSnippetService.new(user_project, current_user, snippet_params).execute
if snippet.persisted? if snippet.persisted?
present snippet, with: Entities::ProjectSnippetV3 present snippet, with: ::API::V3::Entities::ProjectSnippet
else else
render_validation_error!(snippet) render_validation_error!(snippet)
end end
end end
desc 'Update an existing project snippet' do desc 'Update an existing project snippet' do
success Entities::ProjectSnippetV3 success ::API::V3::Entities::ProjectSnippet
end end
params do params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
...@@ -99,7 +99,7 @@ module API ...@@ -99,7 +99,7 @@ module API
snippet_params).execute snippet_params).execute
if snippet.persisted? if snippet.persisted?
present snippet, with: Entities::ProjectSnippetV3 present snippet, with: ::API::V3::Entities::ProjectSnippet
else else
render_validation_error!(snippet) render_validation_error!(snippet)
end end
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment