Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated RecipeController saveOrUpdate method and made it fully reacti… #7

Open
wants to merge 1 commit into
base: binding-validation
Choose a base branch
from

Conversation

seblopez
Copy link

Hi John and staff!
I've made a change to the way RecipeController.saveOrUpdate is resolved using the guidance outlined in https://docs.spring.io/spring/docs/5.0.x/spring-framework-reference/web-reactive.html#webflux-ann-modelattrib-method-args, specifically:
"(...) Spring WebFlux, unlike Spring MVC, supports reactive types in the model, e.g. Mono or io.reactivex.Single. An @ModelAttribute argument can be declared with or without a reactive type wrapper, and it will be resolved accordingly, to the actual value if necessary. Note however that in order to use a BindingResult argument, you must declare the @ModelAttribute argument before it without a reactive type wrapper, as shown earlier. Alternatively, you can handle any errors through the reactive type:
@PostMapping("/owners/{ownerId}/pets/{petId}/edit")
public Mono processSubmit(@Valid @ModelAttribute("pet") Mono petMono) {
return petMono
.flatMap(pet -> {
// ...
})
.onErrorResume(ex -> {
// ...
});
}"

Notice that BindingResult is completely out of the picture and the method is now fully reactive.
All UT tests have been verified, along with testing recipe updates within the app.

Hope you find it useful!

Regards,

Sebastian Lopez

…ve per guidance outlined in https://docs.spring.io/spring/docs/5.0.x/spring-framework-reference/web-reactive.html#webflux-ann-modelattrib-method-args

Specifically:
"(...) Spring WebFlux, unlike Spring MVC, supports reactive types in the model, e.g. Mono<Account> or io.reactivex.Single<Account>. An @ModelAttribute argument can be declared with or without a reactive type wrapper, and it will be resolved accordingly, to the actual value if necessary. Note however that in order to use a BindingResult argument, you must declare the @ModelAttribute argument before it without a reactive type wrapper, as shown earlier. Alternatively, you can handle any errors through the reactive type:
@PostMapping("/owners/{ownerId}/pets/{petId}/edit")
public Mono<String> processSubmit(@Valid @ModelAttribute("pet") Mono<Pet> petMono) {
    return petMono
        .flatMap(pet -> {
            // ...
        })
        .onErrorResume(ex -> {
            // ...
        });
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant