From 72b1a5e8fd271af0a65066659d5c2b060d61178a Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 23 Jan 2023 09:05:38 +0100 Subject: [PATCH] Distinct generated count method from interface in REST Data with Panache Fix https://github.com/quarkusio/quarkus/issues/30515 --- .../deployment/methods/CountMethodImplementor.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/CountMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/CountMethodImplementor.java index efc45733a161a..c3594cdc4c7cd 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/CountMethodImplementor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/CountMethodImplementor.java @@ -4,6 +4,7 @@ import static io.quarkus.rest.data.panache.deployment.utils.SignatureMethodCreator.ofType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import io.quarkus.deployment.Capabilities; import io.quarkus.gizmo.ClassCreator; @@ -41,9 +42,9 @@ public CountMethodImplementor(Capabilities capabilities) { * {@code * @GET * @Path("/count") - * public long count() { + * public Response count(UriInfo uriInfo) { * try { - * return resource.count(); + * return Response.ok(resource.count()); * } catch (Throwable t) { * throw new RestDataPanacheException(t); * } @@ -74,10 +75,13 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res ResourceProperties resourceProperties, FieldDescriptor resourceField) { // Method parameters: sort strings, page index, page size, uri info MethodCreator methodCreator = SignatureMethodCreator.getMethodCreator(RESOURCE_METHOD_NAME, classCreator, - isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, Long.class)); + isNotReactivePanache() ? ofType(Response.class) : ofType(Uni.class, Long.class), + UriInfo.class); + methodCreator.setParameterNames(new String[] { "uriInfo" }); // Add method annotations addGetAnnotation(methodCreator); + addContextAnnotation(methodCreator.getParameterAnnotations(0)); addProducesAnnotation(methodCreator, APPLICATION_JSON); addPathAnnotation(methodCreator, appendToPath(resourceProperties.getPath(RESOURCE_METHOD_NAME), RESOURCE_METHOD_NAME)); addMethodAnnotations(methodCreator, resourceProperties.getMethodAnnotations(RESOURCE_METHOD_NAME));