From 56efaed78ff536d4906de176bf0c99dc612b2e6f Mon Sep 17 00:00:00 2001 From: dix Date: Tue, 24 Oct 2023 11:45:27 +0200 Subject: [PATCH] Exercice 11 : Use mutiny's Uni only, rm Multi mention --- code/exercise_011_Going_Reactive/README.md | 3 +-- .../lunatech/training/quarkus/ProductsResource.java | 12 +----------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/code/exercise_011_Going_Reactive/README.md b/code/exercise_011_Going_Reactive/README.md index ba3a97c..7f33c17 100644 --- a/code/exercise_011_Going_Reactive/README.md +++ b/code/exercise_011_Going_Reactive/README.md @@ -17,8 +17,7 @@ Note: one of the reasons we removed the `quarkus-hibernate-orm-rest-data-panache * Remove the setting `quarkus.datasource.jdbc.url`, and replace it with this setting: ` quarkus.datasource.reactive.url=postgresql://localhost:8765/postgres` * Go to your `Product` class. Delete the old `PanacheEntity` import, and find the proper import to use now. -* Now, go to `ProductsResource`, and make it work again. Note that you can return `Uni` or `Multi` reponses from your resource methods now that you have RESTeasy reactive. - Try two options: returning a `Multi` from the `products()` method, or returning a `Uni>`. What’s the conceptual difference between these? +* Now, go to `ProductsResource`, and make it work again. Note that you can return `Uni` responses from your resource methods now that you have RESTeasy reactive. * For the `PUT` endpoint, do the following: - Start with `Product.findById(id)`, and `flatMap` the resulting `Uni`. - Within the `flatMap`, update the product, and invoke `persistAndFlush` diff --git a/code/exercise_011_Going_Reactive/src/main/java/com/lunatech/training/quarkus/ProductsResource.java b/code/exercise_011_Going_Reactive/src/main/java/com/lunatech/training/quarkus/ProductsResource.java index 7525064..29bbaad 100644 --- a/code/exercise_011_Going_Reactive/src/main/java/com/lunatech/training/quarkus/ProductsResource.java +++ b/code/exercise_011_Going_Reactive/src/main/java/com/lunatech/training/quarkus/ProductsResource.java @@ -1,11 +1,7 @@ package com.lunatech.training.quarkus; -import io.quarkus.hibernate.reactive.panache.common.WithSession; -import io.quarkus.hibernate.reactive.panache.common.WithSessionOnDemand; import io.quarkus.hibernate.reactive.panache.common.WithTransaction; -import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; - import jakarta.validation.Valid; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; @@ -18,13 +14,7 @@ public class ProductsResource { @GET - public Multi products() { - return getAllProducts().toMulti() - .flatMap(list -> Multi.createFrom().iterable(list)); - } - - @WithTransaction - public Uni> getAllProducts(){ + public Uni> products() { return Product.listAll(); }