Skip to content

Commit

Permalink
Allow additional orderBy options when searching (#5395)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann authored Oct 23, 2024
1 parent 4149ad4 commit 61bf506
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1066,17 +1066,14 @@ public ArtifactSearchResultsDto searchArtifacts(Set<SearchFilter> filters, Order
case name:
orderByQuery.append(" ORDER BY coalesce(a.name, a.artifactId)");
break;
case artifactId:
orderByQuery.append(" ORDER BY a.artifactId");
case artifactType:
orderByQuery.append(" ORDER BY a.type");
break;
case groupId:
case artifactId:
case createdOn:
orderByQuery.append(" ORDER BY a.createdOn");
break;
case modifiedOn:
orderByQuery.append(" ORDER BY a.modifiedOn");
break;
case artifactType:
orderByQuery.append(" ORDER BY a.type");
orderByQuery.append(" ORDER BY a." + orderBy.name());
break;
default:
throw new RuntimeException("Sort by " + orderBy.name() + " not supported.");
Expand Down Expand Up @@ -1681,28 +1678,21 @@ public VersionSearchResultsDto searchVersions(Set<SearchFilter> filters, OrderBy
where.append(")");
}

// Add order by to artifact query
// Add order by to query
switch (orderBy) {
case globalId:
orderByQuery.append(" ORDER BY v.globalId");
case name:
orderByQuery.append(" ORDER BY coalesce(v.name, v.version)");
break;
case groupId:
orderByQuery.append(" ORDER BY v.groupId");
break;
case artifactId:
case version:
orderByQuery.append(" ORDER BY v.version");
break;
case name:
orderByQuery.append(" ORDER BY v.name");
break;
case globalId:
case createdOn:
orderByQuery.append(" ORDER BY v.createdOn");
break;
case modifiedOn:
orderByQuery.append(" ORDER BY v.modifiedOn");
orderByQuery.append(" ORDER BY v." + orderBy.name());
break;
default:
break;
throw new RuntimeException("Sort by " + orderBy.name() + " not supported.");
}
orderByQuery.append(" ").append(orderDirection.name());

Expand Down Expand Up @@ -2869,13 +2859,12 @@ public GroupSearchResultsDto searchGroups(Set<SearchFilter> filters, OrderBy ord
// Add order by to artifact query
switch (orderBy) {
case groupId:
orderByQuery.append(" ORDER BY g.groupId");
break;
case createdOn:
case modifiedOn:
orderByQuery.append(" ORDER BY g.").append(orderBy.name());
break;
default:
break;
throw new RuntimeException("Sort by " + orderBy.name() + " not supported.");
}
orderByQuery.append(" ").append(orderDirection.name());

Expand Down
6 changes: 5 additions & 1 deletion common/src/main/resources/META-INF/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3676,6 +3676,7 @@
"ArtifactSortBy": {
"description": "",
"enum": [
"groupId",
"artifactId",
"createdOn",
"modifiedOn",
Expand Down Expand Up @@ -5092,6 +5093,8 @@
"VersionSortBy": {
"description": "",
"enum": [
"groupId",
"artifactId",
"version",
"name",
"createdOn",
Expand All @@ -5104,7 +5107,8 @@
"description": "",
"enum": [
"groupId",
"createdOn"
"createdOn",
"modifiedOn"
],
"type": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion go-sdk/pkg/registryclient-v3/kiota-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"descriptionHash": "D346A2A9A40F1B86E55F338BFB56645B0AE0D95EF3B3E66B14920108B20F119845B8EF22305D5C70D8DFDCC4BA0E39B5A78BD1F19D81AB90587F206B2470163D",
"descriptionHash": "6D428EDE13C8C05F3E9350ADBED7F44A1E6FFE2930A5F0EF8AF63340F89684254673F58AD88E237A968713F30D33CF09EB59BC3D3F08969CB79C3C4444A972C8",
"descriptionLocation": "../../v3.json",
"lockFileVersion": "1.0.0",
"kiotaVersion": "1.19.1",
Expand Down
9 changes: 6 additions & 3 deletions go-sdk/pkg/registryclient-v3/models/artifact_sort_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package models
type ArtifactSortBy int

const (
ARTIFACTID_ARTIFACTSORTBY ArtifactSortBy = iota
GROUPID_ARTIFACTSORTBY ArtifactSortBy = iota
ARTIFACTID_ARTIFACTSORTBY
CREATEDON_ARTIFACTSORTBY
MODIFIEDON_ARTIFACTSORTBY
ARTIFACTTYPE_ARTIFACTSORTBY
NAME_ARTIFACTSORTBY
)

func (i ArtifactSortBy) String() string {
return []string{"artifactId", "createdOn", "modifiedOn", "artifactType", "name"}[i]
return []string{"groupId", "artifactId", "createdOn", "modifiedOn", "artifactType", "name"}[i]
}
func ParseArtifactSortBy(v string) (any, error) {
result := ARTIFACTID_ARTIFACTSORTBY
result := GROUPID_ARTIFACTSORTBY
switch v {
case "groupId":
result = GROUPID_ARTIFACTSORTBY
case "artifactId":
result = ARTIFACTID_ARTIFACTSORTBY
case "createdOn":
Expand Down
5 changes: 4 additions & 1 deletion go-sdk/pkg/registryclient-v3/models/group_sort_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ type GroupSortBy int
const (
GROUPID_GROUPSORTBY GroupSortBy = iota
CREATEDON_GROUPSORTBY
MODIFIEDON_GROUPSORTBY
)

func (i GroupSortBy) String() string {
return []string{"groupId", "createdOn"}[i]
return []string{"groupId", "createdOn", "modifiedOn"}[i]
}
func ParseGroupSortBy(v string) (any, error) {
result := GROUPID_GROUPSORTBY
Expand All @@ -17,6 +18,8 @@ func ParseGroupSortBy(v string) (any, error) {
result = GROUPID_GROUPSORTBY
case "createdOn":
result = CREATEDON_GROUPSORTBY
case "modifiedOn":
result = MODIFIEDON_GROUPSORTBY
default:
return nil, nil
}
Expand Down
12 changes: 9 additions & 3 deletions go-sdk/pkg/registryclient-v3/models/version_sort_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ package models
type VersionSortBy int

const (
VERSION_VERSIONSORTBY VersionSortBy = iota
GROUPID_VERSIONSORTBY VersionSortBy = iota
ARTIFACTID_VERSIONSORTBY
VERSION_VERSIONSORTBY
NAME_VERSIONSORTBY
CREATEDON_VERSIONSORTBY
MODIFIEDON_VERSIONSORTBY
GLOBALID_VERSIONSORTBY
)

func (i VersionSortBy) String() string {
return []string{"version", "name", "createdOn", "modifiedOn", "globalId"}[i]
return []string{"groupId", "artifactId", "version", "name", "createdOn", "modifiedOn", "globalId"}[i]
}
func ParseVersionSortBy(v string) (any, error) {
result := VERSION_VERSIONSORTBY
result := GROUPID_VERSIONSORTBY
switch v {
case "groupId":
result = GROUPID_VERSIONSORTBY
case "artifactId":
result = ARTIFACTID_VERSIONSORTBY
case "version":
result = VERSION_VERSIONSORTBY
case "name":
Expand Down

0 comments on commit 61bf506

Please sign in to comment.