33import com .javatab .authservice .domain .AuthRequest ;
44import com .javatab .authservice .domain .AuthResponse ;
55import com .javatab .authservice .domain .User ;
6+ import com .javatab .authservice .domain .UserEvent ;
67import com .javatab .authservice .security .JwtUserDetailService ;
78import com .javatab .authservice .services .UserService ;
89import lombok .RequiredArgsConstructor ;
10+ import org .springframework .cloud .stream .function .StreamBridge ;
911import org .springframework .web .bind .annotation .*;
1012
1113@ RestController
@@ -14,6 +16,9 @@ public class AuthController {
1416
1517 private final JwtUserDetailService userDetailService ;
1618 private final UserService userService ;
19+ private final StreamBridge streamBridge ;
20+
21+ static final String USER_CREATED_OUTPUT = "userCreatedOutput" ;
1722
1823 @ PostMapping ("/login" )
1924 public AuthResponse login (@ RequestBody AuthRequest request ) throws Exception {
@@ -22,6 +27,10 @@ public AuthResponse login(@RequestBody AuthRequest request) throws Exception {
2227
2328 @ PostMapping ("/register" )
2429 public User registerNewUser (@ RequestBody User user ) {
25- return userService .createNewUser (user );
30+ User newUser = userService .createNewUser (user );
31+ UserEvent userEvent = UserEvent .builder ().username (newUser .getUsername ()).email (newUser .getEmail ()).build ();
32+ boolean sent = streamBridge .send (USER_CREATED_OUTPUT , userEvent );
33+ System .out .println ("Message sent " + sent );
34+ return newUser ;
2635 }
2736}
0 commit comments