File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
src/main/java/dev/mikablondo/hibernate_reactive_test Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,10 @@ public class UserController {
2424 private final UserService userService ;
2525
2626 @ GetMapping
27- public Multi <User > getAllUsers () {
27+ public Multi <User > getUsersByNom (@ RequestParam (required = false ) String nom ) {
28+ if (nom != null ) {
29+ return userService .getUsersByNom (nom );
30+ }
2831 return userService .getAllUsers ();
2932 }
3033
Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ public Multi<UserEntity> findAll() {
3232 ).onItem ().transformToMulti (users -> Multi .createFrom ().iterable (users ));
3333 }
3434
35+ /**
36+ * This method retrieves all users with a specific name from the database.
37+ *
38+ * @param nom the name of the users to be retrieved
39+ * @return a Multi stream of UserEntity objects
40+ */
41+ public Multi <UserEntity > findAll (String nom ) {
42+ return sessionFactory .withSession (session ->
43+ session .createQuery ("from UserEntity where lower(nom) = :nom" , UserEntity .class )
44+ .setParameter ("nom" , nom .toLowerCase ())
45+ .getResultList ()
46+ ).onItem ().transformToMulti (users -> Multi .createFrom ().iterable (users ));
47+ }
48+
3549 /**
3650 * This method creates a new user in the database.
3751 *
Original file line number Diff line number Diff line change @@ -85,4 +85,21 @@ public Uni<User> getUserById(UUID uuid) {
8585 }
8686 });
8787 }
88+
89+ /**
90+ * This method retrieves users by their name from the database.
91+ *
92+ * @param nom the name of the users to be retrieved
93+ * @return a Multi stream of User DTO objects
94+ */
95+ public Multi <User > getUsersByNom (String nom ) {
96+ return userRepository .findAll (nom )
97+ .onItem ().transform (userEntity -> User .builder ()
98+ .id (userEntity .getId ())
99+ .nom (userEntity .getNom ())
100+ .prenom (userEntity .getPrenom ())
101+ .age (userEntity .getAge ())
102+ .metier (userEntity .getMetier ())
103+ .build ());
104+ }
88105}
You can’t perform that action at this time.
0 commit comments