OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#40228] answered some comment questions
Eric Schubertbf96f6496c6e
diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rbindex a441ba928ff..112f4351384 100644--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb@@ -26,27 +26,34 @@# See COPYRIGHT and LICENSE files for more details.#++-# See also: ../storages_api.rb for comments-# ToDo: I've checked the other files and didn't understand anything...+# This class provides definitions for API routes and endpoints for the file_links namespace. It inherits the+# functionality from the Grape REST API framework. It is mounted in lib/api/v3/work_packages/work_packages_api.rb,+# which puts the file_links namespace behind the provided namespace of the work packages api+# -> /api/v3/work_packages/:id/file_links/...module APImodule V3module FileLinksclass FileLinksAPI < ::API::OpenProjectAPI- # Helpers are defined here: https://github.com/ruby-grape/grape#helpers- # ToDo: However, I didn't really understand what this thing does and where it's called+ # helpers are defined by the grape framework. They provide methods that can be called from within the+ # endpoint context.helpers dodef visible_file_links_scope::Storages::FileLink.visible(current_user)endend+ # The `:resources` keyword defines the API namespace -> /api/v3/work_packages/:id/file_links/...resources :file_links do+ # A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_linksget &::API::V3::Utilities::Endpoints::Index.new(model: ::Storages::FileLink,scope: -> { visible_file_links_scope },self_path: -> { api_v3_paths.file_links(params[:id]) }).mount+ # A helper is used to define the behaviour at POST /api/v3/work_packages/:id/file_links.+ # Additional classes are provided, that overwrite standard behaviour for parsing request parameters or+ # rendering the response.post &CreateEndpoint.new(model: ::Storages::FileLink,@@ -55,17 +62,25 @@ module API).mount+ # `route_param` extends the route by a route parameter of the endpoint.+ # The input parameter value is parsed into the `:file_link_id` symbol.route_param :file_link_id, type: Integer, desc: 'File link id' do+ # The after validation hook executes after the validation of the request format, but before any execution+ # inside the endpoint context. Hence, it is a good place to actually fetch the handled resource.after_validation do@file_link = visible_file_links_scope.find(params[:file_link_id])end+ # A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_links/:file_link_idget &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::FileLink).mount+ # A helper is used to define the behaviour at DELETE /api/v3/work_packages/:id/file_links/:file_link_iddelete &::API::V3::Utilities::Endpoints::Delete.new(model: ::Storages::FileLink,process_service: ::Storages::FileLinks::DeleteService).mount+ # Additional API definitions are mounted under the current namespace, hence they are+ # appended to /api/v3/work_packages/:id/file_links/:file_link_id/...mount ::API::V3::FileLinks::FileLinksDownloadAPImount ::API::V3::FileLinks::FileLinksOpenAPIenddiff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rbindex 3d23844dcb8..41af73b5cf3 100644--- a/modules/storages/lib/api/v3/storages/storages_api.rb+++ b/modules/storages/lib/api/v3/storages/storages_api.rb@@ -26,11 +26,10 @@# See COPYRIGHT and LICENSE files for more details.#++-# In understand this file sets up routing for the Storages API based on-# the Grape REST API Framework.-# ToDo: I understand the naming of this file follows the API::V::Storages::StoragesAPI module-# names, just that this starts in storages/lib/?-# Is it Grape that somehow knows how to load this file? What is the Grape load order?+# This class provides definitions for API routes and endpoints for the storages namespace. It inherits the+# functionality from the Grape REST API framework. It is mounted in lib/api/v3/root.rb.+# `modules/storages/lib/` is a defined root directory for grape, providing a root level look up for the namespaces.+# Hence, the modules of the class have to be represented in the directory structure.module APImodule V3module Storages@@ -42,10 +41,10 @@ module APIendend- # ToDo: The "resources" keyword is from config/routes.rb.- # What does "resources" mean in the context of Grape? Just like in routes.rb?+ # The `:resources` keyword defines the API namespace -> /api/v3/storages/...resources :storages do- # Didn't understand route_param in Grape...+ # `route_param` extends the route by a route parameter of the endpoint.+ # The input parameter value is parsed into the `:storage_id` symbol.route_param :storage_id, type: Integer, desc: 'Storage id' do# Execute the do...end lines after parameter validation but before the actual# call to the API method.@@ -55,9 +54,10 @@ module API@storage = visible_storages_scope.find(params[:storage_id])end- # I understand that the line below defined a reaction to a GET request...- # ToDo: What is this ampersand "&" before the ::API?- # ToDo: Any documentation on API endpoints?+ # A helper is used to define the behaviour at GET /api/v3/storages/:storage_id+ # The endpoint helper standardizes a lot of the parsing, validation and rendering logic.+ # The safe navigation operator (&) is used to not break the whole API when an error occurs+ # mounting this endpointget &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::Storage).mountendend