1
- package guru .qa .nifflerauth .controller ;
1
+ package guru .qa .niffler .controller ;
2
2
3
- import guru .qa .nifflerauth .model .RegistrationModel ;
4
- import guru .qa .nifflerauth .service .UserService ;
3
+ import guru .qa .niffler .model .RegistrationModel ;
4
+ import guru .qa .niffler .model .UserJson ;
5
+ import guru .qa .niffler .service .UserService ;
5
6
import jakarta .annotation .Nonnull ;
6
7
import jakarta .servlet .http .HttpServletResponse ;
7
8
import jakarta .validation .Valid ;
10
11
import org .springframework .beans .factory .annotation .Autowired ;
11
12
import org .springframework .beans .factory .annotation .Value ;
12
13
import org .springframework .dao .DataIntegrityViolationException ;
14
+ import org .springframework .kafka .core .KafkaTemplate ;
13
15
import org .springframework .stereotype .Controller ;
14
16
import org .springframework .ui .Model ;
15
17
import org .springframework .validation .BeanPropertyBindingResult ;
@@ -32,12 +34,14 @@ public class RegisterController {
32
34
33
35
private final UserService userService ;
34
36
private final String nifflerFrontUri ;
37
+ private final KafkaTemplate kafkaTemplate ;
35
38
36
39
@ Autowired
37
40
public RegisterController (UserService userService ,
38
- @ Value ("${niffler-front.base-uri}" ) String nifflerFrontUri ) {
41
+ @ Value ("${niffler-front.base-uri}" ) String nifflerFrontUri , KafkaTemplate kafkaTemplate ) {
39
42
this .userService = userService ;
40
43
this .nifflerFrontUri = nifflerFrontUri ;
44
+ this .kafkaTemplate = kafkaTemplate ;
41
45
}
42
46
43
47
@ GetMapping ("/register" )
@@ -59,6 +63,10 @@ public String registerUser(@Valid @ModelAttribute RegistrationModel registration
59
63
registrationModel .getUsername (),
60
64
registrationModel .getPassword ()
61
65
);
66
+ UserJson kafkaMsg = new UserJson ();
67
+ kafkaMsg .setUsername (registeredUserName );
68
+ kafkaTemplate .send ("users" , kafkaMsg );
69
+
62
70
response .setStatus (HttpServletResponse .SC_CREATED );
63
71
model .addAttribute (MODEL_USERNAME_ATTR , registeredUserName );
64
72
} catch (DataIntegrityViolationException e ) {
0 commit comments