Commit a195c841 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Adds project_path sorting to package groups api

parent 2b3ac7af
...@@ -70,6 +70,8 @@ class Packages::Package < ApplicationRecord ...@@ -70,6 +70,8 @@ class Packages::Package < ApplicationRecord
scope :order_type_desc, -> { reorder('package_type DESC') } scope :order_type_desc, -> { reorder('package_type DESC') }
scope :order_project_name, -> { joins(:project).reorder('projects.name ASC') } scope :order_project_name, -> { joins(:project).reorder('projects.name ASC') }
scope :order_project_name_desc, -> { joins(:project).reorder('projects.name DESC') } scope :order_project_name_desc, -> { joins(:project).reorder('projects.name DESC') }
scope :order_project_path, -> { joins(:project).reorder('projects.path ASC, id ASC') }
scope :order_project_path_desc, -> { joins(:project).reorder('projects.path DESC, id DESC') }
def self.for_projects(projects) def self.for_projects(projects)
return none unless projects.any? return none unless projects.any?
...@@ -107,6 +109,8 @@ class Packages::Package < ApplicationRecord ...@@ -107,6 +109,8 @@ class Packages::Package < ApplicationRecord
when 'type_desc' then order_type_desc when 'type_desc' then order_type_desc
when 'project_name_asc' then order_project_name when 'project_name_asc' then order_project_name
when 'project_name_desc' then order_project_name_desc when 'project_name_desc' then order_project_name_desc
when 'project_path_asc' then order_project_path
when 'project_path_desc' then order_project_path_desc
else else
order_created_desc order_created_desc
end end
......
---
title: Adds project_path sorting to group package API
merge_request: 24833
author:
type: added
...@@ -21,7 +21,7 @@ module API ...@@ -21,7 +21,7 @@ module API
end end
params do params do
use :pagination use :pagination
optional :order_by, type: String, values: %w[created_at name version type], default: 'created_at', optional :order_by, type: String, values: %w[created_at name version type project_path], default: 'created_at',
desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.' desc: 'Return packages ordered by `created_at`, `name`, `version` or `type` fields.'
optional :sort, type: String, values: %w[asc desc], default: 'asc', optional :sort, type: String, values: %w[asc desc], default: 'asc',
desc: 'Return packages sorted in `asc` or `desc` order.' desc: 'Return packages sorted in `asc` or `desc` order.'
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe API::GroupPackages do describe API::GroupPackages do
let(:group) { create(:group, :public) } let(:group) { create(:group, :public) }
let(:project) { create(:project, :public, namespace: group) } let(:project) { create(:project, :public, namespace: group, name: 'project A') }
let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") } let!(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') } let!(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -54,6 +54,13 @@ describe API::GroupPackages do ...@@ -54,6 +54,13 @@ describe API::GroupPackages do
it_behaves_like 'package sorting', 'type' do it_behaves_like 'package sorting', 'type' do
let(:packages) { [package3, package1, package2] } let(:packages) { [package3, package1, package2] }
end end
it_behaves_like 'package sorting', 'project_path' do
let(:another_project) { create(:project, :public, namespace: group, name: 'project B') }
let!(:package4) { create(:npm_package, project: another_project, version: '3.1.0', name: "@#{project.root_namespace.path}/bar") }
let(:packages) { [package1, package2, package3, package4] }
end
end end
context 'with private group' do context 'with private group' do
......
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