Class AddMethodImplementor

    • Constructor Detail

      • AddMethodImplementor

        public AddMethodImplementor​(io.quarkus.deployment.Capabilities capabilities)
    • Method Detail

      • implementInternal

        protected void implementInternal​(io.quarkus.gizmo.ClassCreator classCreator,
                                         ResourceMetadata resourceMetadata,
                                         ResourceProperties resourceProperties,
                                         io.quarkus.gizmo.FieldDescriptor resourceField)
        Generate JAX-RS POST method. The RESTEasy Classic version exposes RestDataResource.add(Object). Generated code looks more or less like this:
         
             @POST
             @Path("")
             @Consumes({"application/json"})
             @Produces({"application/json"})
             @LinkResource(
                 rel = "add",
                 entityClassName = "com.example.Entity"
             )
             public Response add(Entity entityToSave) {
                 try {
                     Entity entity = restDataResource.add(entityToSave);
                     String location = new ResourceLinksProvider().getSelfLink(entity);
                     if (location != null) {
                         ResponseBuilder responseBuilder = Response.status(201);
                         responseBuilder.entity(entity);
                         responseBuilder.location(URI.create(location));
                         return responseBuilder.build();
                     } else {
                         throw new RuntimeException("Could not extract a new entity URL")
                     }
                 } catch (Throwable t) {
                     throw new RestDataPanacheException(t);
                 }
             }
         
         
        The RESTEasy Reactive version exposes ReactiveRestDataResource.add(Object) and the generated code looks more or less like this:
         
             @POST
             @Path("")
             @Consumes({"application/json"})
             @Produces({"application/json"})
             @LinkResource(
                 rel = "add",
                 entityClassName = "com.example.Entity"
             )
             public Uni<Response> add(Entity entityToSave) {
                 return restDataResource.add(entityToSave).map(entity -> {
                     String location = new ResourceLinksProvider().getSelfLink(entity);
                     if (location != null) {
                         ResponseBuilder responseBuilder = Response.status(201);
                         responseBuilder.entity(entity);
                         responseBuilder.location(URI.create(location));
                         return responseBuilder.build();
                     } else {
                         throw new RuntimeException("Could not extract a new entity URL")
                     }
                 }).onFailure().invoke(t -> throw new RestDataPanacheException(t));
             }
         
         
        Specified by:
        implementInternal in class StandardMethodImplementor