2021-11-12 04:10:03 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
class Topics < ::API::Base
|
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
feature_category :projects
|
|
|
|
|
|
|
|
desc 'Get topics' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.5.'
|
|
|
|
success Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :search, type: String, desc: 'Return list of topics matching the search criteria'
|
2022-08-03 23:10:53 -04:00
|
|
|
optional :without_projects, type: Boolean, desc: 'Return list of topics without assigned projects'
|
2021-11-12 04:10:03 -05:00
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get 'topics' do
|
|
|
|
topics = ::Projects::TopicsFinder.new(params: declared_params(include_missing: false)).execute
|
|
|
|
|
|
|
|
present paginate(topics), with: Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get topic' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.5.'
|
|
|
|
success Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'ID of project topic'
|
|
|
|
end
|
|
|
|
get 'topics/:id' do
|
|
|
|
topic = ::Projects::Topic.find(params[:id])
|
|
|
|
|
|
|
|
present topic, with: Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Create a topic' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.5.'
|
|
|
|
success Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
params do
|
2022-04-21 14:10:22 -04:00
|
|
|
requires :name, type: String, desc: 'Slug (name)'
|
|
|
|
requires :title, type: String, desc: 'Title'
|
2021-11-12 04:10:03 -05:00
|
|
|
optional :description, type: String, desc: 'Description'
|
2022-10-19 11:15:15 -04:00
|
|
|
optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'Avatar image for topic',
|
|
|
|
documentation: { type: 'file' }
|
2021-11-12 04:10:03 -05:00
|
|
|
end
|
|
|
|
post 'topics' do
|
|
|
|
authenticated_as_admin!
|
|
|
|
|
|
|
|
topic = ::Projects::Topic.new(declared_params(include_missing: false))
|
|
|
|
|
|
|
|
if topic.save
|
|
|
|
present topic, with: Entities::Projects::Topic
|
|
|
|
else
|
|
|
|
render_validation_error!(topic)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Update a topic' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.5.'
|
|
|
|
success Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'ID of project topic'
|
2022-04-21 14:10:22 -04:00
|
|
|
optional :name, type: String, desc: 'Slug (name)'
|
|
|
|
optional :title, type: String, desc: 'Title'
|
2021-11-12 04:10:03 -05:00
|
|
|
optional :description, type: String, desc: 'Description'
|
2022-10-19 11:15:15 -04:00
|
|
|
optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'Avatar image for topic',
|
|
|
|
documentation: { type: 'file' }
|
2021-11-12 04:10:03 -05:00
|
|
|
end
|
|
|
|
put 'topics/:id' do
|
|
|
|
authenticated_as_admin!
|
|
|
|
|
|
|
|
topic = ::Projects::Topic.find(params[:id])
|
|
|
|
|
2021-12-17 07:16:21 -05:00
|
|
|
topic.remove_avatar! if params.key?(:avatar) && params[:avatar].nil?
|
|
|
|
|
2021-11-12 04:10:03 -05:00
|
|
|
if topic.update(declared_params(include_missing: false))
|
|
|
|
present topic, with: Entities::Projects::Topic
|
|
|
|
else
|
|
|
|
render_validation_error!(topic)
|
|
|
|
end
|
|
|
|
end
|
2022-02-22 04:18:00 -05:00
|
|
|
|
|
|
|
desc 'Delete a topic' do
|
|
|
|
detail 'This feature was introduced in GitLab 14.9.'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'ID of project topic'
|
|
|
|
end
|
|
|
|
delete 'topics/:id' do
|
|
|
|
authenticated_as_admin!
|
|
|
|
|
|
|
|
topic = ::Projects::Topic.find(params[:id])
|
|
|
|
|
|
|
|
destroy_conditionally!(topic)
|
|
|
|
end
|
2022-09-06 02:10:18 -04:00
|
|
|
|
|
|
|
desc 'Merge topics' do
|
|
|
|
detail 'This feature was introduced in GitLab 15.4.'
|
|
|
|
success Entities::Projects::Topic
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :source_topic_id, type: Integer, desc: 'ID of source project topic'
|
|
|
|
requires :target_topic_id, type: Integer, desc: 'ID of target project topic'
|
|
|
|
end
|
|
|
|
post 'topics/merge' do
|
|
|
|
authenticated_as_admin!
|
|
|
|
|
|
|
|
source_topic = ::Projects::Topic.find(params[:source_topic_id])
|
|
|
|
target_topic = ::Projects::Topic.find(params[:target_topic_id])
|
|
|
|
|
|
|
|
response = ::Topics::MergeService.new(source_topic, target_topic).execute
|
|
|
|
render_api_error!(response.message, :bad_request) if response.error?
|
|
|
|
|
|
|
|
present target_topic, with: Entities::Projects::Topic
|
|
|
|
end
|
2021-11-12 04:10:03 -05:00
|
|
|
end
|
|
|
|
end
|