diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-12-03 09:23:38 -0600 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-12-04 08:44:21 -0600 |
commit | 2674830e4df3f6509bd63ebfd048bc6a4e7053ab (patch) | |
tree | ddf982d821a7ce32d275f841f6ce3fb14f5a78a9 /app/serializers/issue_board_entity.rb | |
parent | bba23151a1c0b4dff8f2c31301c5d0589876251d (diff) | |
download | gitlab-ce-2674830e4df3f6509bd63ebfd048bc6a4e7053ab.tar.gz |
Extract code into IssueBoardEntity
Diffstat (limited to 'app/serializers/issue_board_entity.rb')
-rw-r--r-- | app/serializers/issue_board_entity.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/app/serializers/issue_board_entity.rb b/app/serializers/issue_board_entity.rb new file mode 100644 index 00000000000..6a9e9638e70 --- /dev/null +++ b/app/serializers/issue_board_entity.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +class IssueBoardEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :iid + expose :title + + expose :confidential + expose :due_date + expose :project_id + expose :relative_position + expose :weight, if: -> (*) { respond_to?(:weight) } + + expose :project do |issue| + API::Entities::Project.represent issue.project, only: [:id, :path] + end + + expose :milestone, expose_nil: false do |issue| + API::Entities::Project.represent issue.milestone, only: [:id, :title] + end + + expose :assignees do |issue| + API::Entities::UserBasic.represent issue.assignees, only: [:id, :name, :username, :avatar_url] + end + + expose :labels do |issue| + LabelEntity.represent issue.labels, project: issue.project, only: [:id, :title, :description, :color, :priority, :text_color] + end + + expose :reference_path, if: -> (issue) { issue.project } do |issue, options| + options[:include_full_project_path] ? issue.to_reference(full: true) : issue.to_reference + end + + expose :real_path, if: -> (issue) { issue.project } do |issue| + project_issue_path(issue.project, issue) + end + + expose :issue_sidebar_endpoint, if: -> (issue) { issue.project } do |issue| + project_issue_path(issue.project, issue, format: :json, serializer: 'sidebar') + end + + expose :toggle_subscription_endpoint, if: -> (issue) { issue.project } do |issue| + toggle_subscription_project_issue_path(issue.project, issue) + end + + expose :assignable_labels_endpoint, if: -> (issue) { issue.project } do |issue| + project_labels_path(issue.project, format: :json, include_ancestor_groups: true) + end +end |