Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to filter extensions by id to REST API #611

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions api/src/main/kotlin/io/quarkus/code/rest/CodeQuarkusResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,17 @@ class CodeQuarkusResource {
schema = Schema(implementation = CodeQuarkusExtension::class, type = SchemaType.ARRAY)
)]
)
fun extensions(@QueryParam("platformOnly") @DefaultValue("true") platformOnly: Boolean): Response {
fun extensions(
@QueryParam("platformOnly") @DefaultValue("true") platformOnly: Boolean,
@QueryParam("id") extensionId: String?
): Response {
var extensions = platformService.recommendedCodeQuarkusExtensions
if (platformOnly) {
extensions = extensions.filter { it.platform }
}
if (extensionId != null) {
extensions = extensions.filter { it.id == extensionId }
}
val lastUpdated = platformService.cacheLastUpdated
return Response.ok(extensions).header(LAST_MODIFIED_HEADER, lastUpdated.format(formatter)).build()
}
Expand All @@ -162,12 +168,16 @@ class CodeQuarkusResource {
)
fun extensionsForStream(
@PathParam("streamKey") streamKey: String,
@QueryParam("platformOnly") @DefaultValue("true") platformOnly: Boolean
@QueryParam("platformOnly") @DefaultValue("true") platformOnly: Boolean,
@QueryParam("id") extensionId: String?
): Response {
var extensions = platformService.getCodeQuarkusExtensions(streamKey)
if (platformOnly) {
extensions = extensions?.filter { it.platform }
}
if (extensionId != null) {
extensions = extensions.filter { it.id == extensionId }
}
val lastUpdated = platformService.cacheLastUpdated
return Response.ok(extensions).header(LAST_MODIFIED_HEADER, lastUpdated.format(formatter)).build()
}
Expand Down Expand Up @@ -271,4 +281,4 @@ class CodeQuarkusResource {
.build()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,19 @@ class CodeQuarkusResourceTest {
.body("$.size()", greaterThan(50))
}

@Test
@DisplayName("Should return the requested extension")
fun testExtensionById() {
given()
.`when`().get("/api/extensions?id=io.quarkus:quarkus-resteasy")
.then()
.log().ifValidationFails()
.statusCode(200)
.contentType(MediaType.APPLICATION_JSON)
.body("$.size()", equalTo(1))
.body("[0].id", equalTo("io.quarkus:quarkus-resteasy"))
}

@Test
@DisplayName("Should generate a gradle project")
fun testGradle() {
Expand Down