Skip to content

Commit

Permalink
Merge pull request #852 from amvanbaren/bugfix/issue-841
Browse files Browse the repository at this point in the history
Make versions endpoint case insensitive
  • Loading branch information
amvanbaren authored Jan 30, 2024
2 parents c62c821 + de27d8b commit 485c96f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ public ExtensionJson getExtension(String namespace, String extensionName, String
@Override
public VersionsJson getVersions(String namespace, String extension, String targetPlatform, int size, int offset) {
var pageRequest = PageRequest.of((offset/size), size);
var page = targetPlatform == null
? repositories.findActiveVersionStringsSorted(namespace, extension, pageRequest)
: repositories.findActiveVersionStringsSorted(namespace, extension, targetPlatform, pageRequest);
var page = repositories.findActiveVersionStringsSorted(namespace, extension, targetPlatform, pageRequest);

var json = new VersionsJson();
json.offset = (int) page.getPageable().getOffset();
json.totalSize = (int) page.getTotalElements();
var namespaceLowerCase = namespace.toLowerCase();
var extensionLowerCase = extension.toLowerCase();
json.versions = page.get()
.collect(Collectors.toMap(
version -> version,
version -> UrlUtil.createApiVersionUrl(UrlUtil.getBaseUrl(), namespace, extension, targetPlatform, version),
version -> UrlUtil.createApiVersionUrl(UrlUtil.getBaseUrl(), namespaceLowerCase, extensionLowerCase, targetPlatform, version),
(v1, v2) -> v1,
LinkedHashMap::new
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public Page<String> findActiveVersionStringsSorted(String namespace, String exte
.join(EXTENSION).on(EXTENSION.ID.eq(EXTENSION_VERSION.EXTENSION_ID))
.join(NAMESPACE).on(NAMESPACE.ID.eq(EXTENSION.NAMESPACE_ID))
.where(EXTENSION_VERSION.ACTIVE.eq(true))
.and(NAMESPACE.NAME.eq(namespace))
.and(EXTENSION.NAME.eq(extension));
.and(NAMESPACE.NAME.equalIgnoreCase(namespace))
.and(EXTENSION.NAME.equalIgnoreCase(extension));

if(targetPlatform != null) {
totalQuery = totalQuery.and(EXTENSION_VERSION.TARGET_PLATFORM.eq(targetPlatform));
}

var conditions = new ArrayList<Condition>();
conditions.add(EXTENSION_VERSION.ACTIVE.eq(true));
conditions.add(NAMESPACE.NAME.eq(namespace));
conditions.add(EXTENSION.NAME.eq(extension));
conditions.add(NAMESPACE.NAME.equalIgnoreCase(namespace));
conditions.add(EXTENSION.NAME.equalIgnoreCase(extension));
if(targetPlatform != null) {
conditions.add(EXTENSION_VERSION.TARGET_PLATFORM.eq(targetPlatform));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ public Page<ExtensionVersion> findActiveVersionsSorted(String namespace, String
return extensionVersionRepo.findByTargetPlatformAndExtensionNameIgnoreCaseAndExtensionNamespaceNameIgnoreCase(targetPlatform, extension, namespace, page.withSort(VERSIONS_SORT));
}

public Page<String> findActiveVersionStringsSorted(String namespace, String extension, PageRequest page) {
return extensionVersionJooqRepo.findActiveVersionStringsSorted(namespace, extension, null, page);
}

public Page<String> findActiveVersionStringsSorted(String namespace, String extension, String targetPlatform, PageRequest page) {
return extensionVersionJooqRepo.findActiveVersionStringsSorted(namespace, extension, targetPlatform, page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ void testExecuteQueries() {
() -> repositories.deleteAllKeyPairs(),
() -> repositories.findActiveVersionsSorted("namespaceName", "extensionName", PageRequest.ofSize(1)),
() -> repositories.findActiveVersionsSorted("namespaceName", "extensionName", "targetPlatform", PageRequest.ofSize(1)),
() -> repositories.findActiveVersionStringsSorted("namespaceName", "extensionName", PageRequest.ofSize(1)),
() -> repositories.findActiveVersionStringsSorted("namespaceName", "extensionName", "targetPlatform", PageRequest.ofSize(1)),
() -> repositories.findVersionStringsSorted(extension, "targetPlatform", true),
() -> repositories.findVersionStringsSorted(extension, "targetPlatform", true),
Expand Down

0 comments on commit 485c96f

Please sign in to comment.