Skip to content

Commit

Permalink
paginate findBySourcePackageNameInAndGardenlinuxVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilhe committed Sep 12, 2024
1 parent 0055a03 commit ea6123a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion api-examples/Get CVEs by Gardenlinux Version.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ meta {
}

get {
url: {{schema_hostname_port}}/v1/cves/1592.0?sortBy=cveId
url: {{schema_hostname_port}}/v1/cves/1592.0?sortBy=cveId&pageNumber=1&pageSize=3
body: none
auth: none
}

params:query {
sortBy: cveId
pageNumber: 1
pageSize: 3
}
10 changes: 8 additions & 2 deletions src/main/java/io/gardenlinux/glvd/GlvdController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ ResponseEntity<List<SourcePackageCve>> getCveDistro(

@GetMapping("/cves/{gardenlinuxVersion}/packages/{packageList}")
ResponseEntity<List<SourcePackageCve>> getCvePackages(
@PathVariable final String gardenlinuxVersion, @PathVariable final String packageList) {
var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList);
@PathVariable final String gardenlinuxVersion,
@PathVariable final String packageList,
@RequestParam(defaultValue = "cveId") final String sortBy,
@RequestParam(defaultValue = "ASC") final String sortOrder,
@RequestParam(required = false) final String pageNumber,
@RequestParam(required = false) final String pageSize
) {
var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize));
return ResponseEntity.ok().body(cveForPackages);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/gardenlinux/glvd/GlvdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public List<SourcePackageCve> getCveForDistribution(String gardenlinuxVersion, S
return sourcePackageCveRepository.findByGardenlinuxVersion(gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions));
}

public List<SourcePackageCve> getCveForPackages(String gardenlinuxVersion, String packages) {
return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion("{" + packages + "}", gardenlinuxVersion);
public List<SourcePackageCve> getCveForPackages(String gardenlinuxVersion, String packages, SortAndPageOptions sortAndPageOptions) {
return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion("{" + packages + "}", gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions));
}

public List<SourcePackage> getPackagesForDistro(String gardenlinuxVersion, SortAndPageOptions sortAndPageOptions) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/gardenlinux/glvd/UiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public String getCveForDistribution(
public String getCveForPackages(
@RequestParam(name = "gardenlinuxVersion", required = true) String gardenlinuxVersion,
@RequestParam(name = "packages", required = true) String packages,
@RequestParam(defaultValue = "cveId") final String sortBy,
@RequestParam(defaultValue = "ASC") final String sortOrder,
@RequestParam(required = false) final String pageNumber,
@RequestParam(required = false) final String pageSize,
Model model
) {
var sourcePackageCves = glvdService.getCveForPackages(gardenlinuxVersion, packages);
var sourcePackageCves = glvdService.getCveForPackages(gardenlinuxVersion, packages, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize));
model.addAttribute("sourcePackageCves", sourcePackageCves);
model.addAttribute("gardenlinuxVersion", gardenlinuxVersion);
model.addAttribute("packages", packages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public interface SourcePackageCveRepository extends JpaRepository<SourcePackageC
// would be nice if we did not need a native query here
// is this (the in-array search for packages) possible in any other way with spring data jpa?
// fixme: does not support sorting, cf https://github.com/spring-projects/spring-data-jpa/issues/2504#issuecomment-1527743003
// pagination seems to work ok
@Query(value = """
SELECT * FROM sourcepackagecve
WHERE source_package_name = ANY(:source_package_names ::TEXT[]) AND gardenlinux_version = :gardenlinux_version
""", nativeQuery = true)
List<SourcePackageCve> findBySourcePackageNameInAndGardenlinuxVersion(@Param("source_package_names") String source_package_names, @Param("gardenlinux_version") String gardenlinux_version);
List<SourcePackageCve> findBySourcePackageNameInAndGardenlinuxVersion(@Param("source_package_names") String source_package_names, @Param("gardenlinux_version") String gardenlinux_version, Pageable pageable);
}

0 comments on commit ea6123a

Please sign in to comment.