Welcome to mirror list, hosted at ThFree Co, Russian Federation.

topics.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9c2bcc2da80c4ba07102e50c12beb930aa0c2ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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'
      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
      requires :name, type: String, desc: 'Name'
      optional :description, type: String, desc: 'Description'
      optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'Avatar image for topic'
    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'
      optional :name, type: String, desc: 'Name'
      optional :description, type: String, desc: 'Description'
      optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'Avatar image for topic'
    end
    put 'topics/:id' do
      authenticated_as_admin!

      topic = ::Projects::Topic.find(params[:id])

      topic.remove_avatar! if params.key?(:avatar) && params[:avatar].nil?

      if topic.update(declared_params(include_missing: false))
        present topic, with: Entities::Projects::Topic
      else
        render_validation_error!(topic)
      end
    end
  end
end