Commit e830bf42 authored by Sashi's avatar Sashi Committed by Mayra Cabrera

Relocate Nuget presenter helpers to presenters module

parent 0b00a5e1
---
title: Relocate Nuget presenter helpers to presenters module
merge_request: 31985
author: Sashi Kumar
type: other
......@@ -3,7 +3,7 @@
module Packages
module Nuget
class PackageMetadataPresenter
include API::Helpers::Packages::Nuget::MetadataPresenterHelpers
include Packages::Nuget::PresenterHelpers
def initialize(package)
@package = package
......
......@@ -3,7 +3,7 @@
module Packages
module Nuget
class PackagesMetadataPresenter
include API::Helpers::Packages::Nuget::MetadataPresenterHelpers
include Packages::Nuget::PresenterHelpers
include Gitlab::Utils::StrongMemoize
COUNT = 1.freeze
......
# frozen_string_literal: true
module Packages
module Nuget
module PresenterHelpers
include ::API::Helpers::RelatedResourcesHelpers
BLANK_STRING = ''
EMPTY_ARRAY = [].freeze
private
def json_url_for(package)
path = api_v4_projects_packages_nuget_metadata_package_name_package_version_path(
{
id: package.project_id,
package_name: package.name,
package_version: package.version,
format: '.json'
},
true
)
expose_url(path)
end
def archive_url_for(package)
path = api_v4_projects_packages_nuget_download_package_name_package_version_package_filename_path(
{
id: package.project_id,
package_name: package.name,
package_version: package.version,
package_filename: package.package_files.last&.file_name
},
true
)
expose_url(path)
end
def catalog_entry_for(package)
{
json_url: json_url_for(package),
authors: BLANK_STRING,
dependencies: EMPTY_ARRAY,
package_name: package.name,
package_version: package.version,
archive_url: archive_url_for(package),
summary: BLANK_STRING,
tags: tags_for(package)
}
end
def base_path_for(package)
api_v4_projects_packages_nuget_path(id: package.project_id)
end
def tags_for(package)
package.tag_names.join(::Packages::Tag::NUGET_TAGS_SEPARATOR)
end
end
end
end
......@@ -3,7 +3,7 @@
module Packages
module Nuget
class SearchResultsPresenter
include API::Helpers::Packages::Nuget::MetadataPresenterHelpers
include Packages::Nuget::PresenterHelpers
include Gitlab::Utils::StrongMemoize
delegate :total_count, to: :@search
......
# frozen_string_literal: true
module API
module Helpers
module Packages
module Nuget
module MetadataPresenterHelpers
include ::API::Helpers::RelatedResourcesHelpers
include ::API::Helpers::PackagesHelpers
BLANK_STRING = ''
EMPTY_ARRAY = [].freeze
private
def json_url_for(package)
path = api_v4_projects_packages_nuget_metadata_package_name_package_version_path(
{
id: package.project.id,
package_name: package.name,
package_version: package.version,
format: '.json'
},
true
)
expose_url(path)
end
def archive_url_for(package)
path = api_v4_projects_packages_nuget_download_package_name_package_version_package_filename_path(
{
id: package.project.id,
package_name: package.name,
package_version: package.version,
package_filename: package.package_files.last&.file_name
},
true
)
expose_url(path)
end
def catalog_entry_for(package)
{
json_url: json_url_for(package),
authors: BLANK_STRING,
dependencies: EMPTY_ARRAY,
package_name: package.name,
package_version: package.version,
archive_url: archive_url_for(package),
summary: BLANK_STRING,
tags: tags_for(package)
}
end
def base_path_for(package)
api_v4_projects_packages_nuget_path(id: package.project.id)
end
def tags_for(package)
package.tag_names.join(::Packages::Tag::NUGET_TAGS_SEPARATOR)
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment