11package flipnote .apigateway .client ;
22
3+ import com .fasterxml .jackson .annotation .JsonProperty ;
34import org .springframework .beans .factory .annotation .Value ;
5+ import org .springframework .core .ParameterizedTypeReference ;
6+ import org .springframework .http .MediaType ;
47import org .springframework .stereotype .Component ;
58import org .springframework .web .reactive .function .client .WebClient ;
69import reactor .core .publisher .Mono ;
@@ -19,12 +22,24 @@ public TokenValidationClient(@Value("${app.user-service.url}") String userServic
1922 public Mono <TokenValidationResponse > validateToken (String token ) {
2023 return webClient .post ()
2124 .uri ("/v1/auth/token/validate" )
25+ .contentType (MediaType .APPLICATION_JSON )
2226 .bodyValue (new TokenValidationRequest (token ))
2327 .retrieve ()
24- .bodyToMono (TokenValidationResponse .class );
28+ .bodyToMono (new ParameterizedTypeReference <ApiResponse <TokenValidationResponse >>() {})
29+ .map (ApiResponse ::data );
2530 }
2631
27- public record TokenValidationRequest (String token ) {}
32+ public record TokenValidationRequest (
33+ @ JsonProperty ("token" ) String token ) {}
2834
29- public record TokenValidationResponse (Long userId , String email , String role ) {}
35+ public record TokenValidationResponse (
36+ @ JsonProperty ("userId" ) Long userId ,
37+ @ JsonProperty ("email" ) String email ,
38+ @ JsonProperty ("role" ) String role ) {}
39+
40+ public record ApiResponse <T >(
41+ @ JsonProperty ("status" ) int status ,
42+ @ JsonProperty ("code" ) String code ,
43+ @ JsonProperty ("message" ) String message ,
44+ @ JsonProperty ("data" ) T data ) {}
3045}
0 commit comments