-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[58521] API endpoint for fetching a custom field item's branch
- Added OpenAPI spec for new endpoint - Added new API endpoint: /api/v3/custom_field_items/{id}/branch - Used HierarchicalItemService to retrieve branch for item
- Loading branch information
Andreas Pfohl
committed
Nov 6, 2024
1 parent
f9b83ef
commit a8965fe
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# /api/v3/custom_field_items/{id}/branch | ||
--- | ||
get: | ||
summary: Get a custom field hierarchy item's branch | ||
operationId: get_custom_field_item_branch | ||
description: |- | ||
Retrieves the branch of a single custom field item specified by its unique identifier. | ||
A branch is list of all ancestors, starting with the root item and finishing with the item itself. | ||
parameters: | ||
- name: id | ||
description: The custom field item's unique identifier | ||
in: path | ||
example: '42' | ||
required: true | ||
schema: | ||
type: integer | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/hal+json: | ||
schema: | ||
$ref: '../components/schemas/hierarchy_item_collection_model.yml' | ||
examples: | ||
'simple response': | ||
$ref: '../components/examples/hierarchy_item_collection_response.yml' | ||
'403': | ||
description: Returned if the user is not logged in. | ||
content: | ||
application/hal+json: | ||
schema: | ||
$ref: '../components/schemas/error_response.yml' | ||
examples: | ||
response: | ||
value: | ||
_type: Error | ||
errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission | ||
message: You are not authorized to access this resource. | ||
'404': | ||
description: Returned if the custom field does not exist. | ||
content: | ||
application/hal+json: | ||
schema: | ||
$ref: '../components/schemas/error_response.yml' | ||
examples: | ||
response: | ||
value: | ||
_type: Error | ||
errorIdentifier: urn:openproject-org:api:v3:errors:NotFound | ||
message: The requested resource could not be found. | ||
'422': | ||
description: Returned if the custom field is not of type hierarchy. | ||
content: | ||
application/hal+json: | ||
schema: | ||
$ref: '../components/schemas/error_response.yml' | ||
examples: | ||
response: | ||
value: | ||
_type: Error | ||
errorIdentifier: urn:openproject-org:api:v3:errors:UnprocessableContent | ||
message: The requested custom field resource is of wrong type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module API | ||
module V3 | ||
module CustomFields | ||
module Hierarchy | ||
class ItemBranchAPI < ::API::OpenProjectAPI | ||
include Dry::Monads[:result] | ||
|
||
resource :branch do | ||
get do | ||
::CustomFields::Hierarchy::HierarchicalItemService | ||
.new | ||
.get_branch(item: @custom_field_item) | ||
.either( | ||
->(items) do | ||
self_link = api_v3_paths.custom_field_item(@custom_field_item.id) | ||
HierarchyItemCollectionRepresenter.new(items, self_link:, current_user:) | ||
end, | ||
->(error) do | ||
msg = "#{I18n.t('api_v3.errors.code_500')} #{error}" | ||
raise ::API::Errors::InternalError.new(msg) | ||
end | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |