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

reactive: Correctly prepare delete endpoint response to send response headers #18569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,6 @@ public class <%= entityClass %>Resource {
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/<%= entityApiUrl %>/{id}")
<%_ if (reactive) { _%>
@ResponseStatus(code = HttpStatus.NO_CONTENT)
<%_ } _%>
public <% if (reactive) { %>Mono<<% } %>ResponseEntity<Void><% if (reactive) { %>><% } %> delete<%= entityClass %>(@PathVariable <%= primaryKey.type %> id) {
log.debug("REST request to delete <%= entityClass %> : {}", id);
<%- include('../../common/delete_template', {viaService: viaService, fromResource: true}); -%>
Expand All @@ -418,8 +415,8 @@ public class <%= entityClass %>Resource {
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, <%= enableTranslation %>, ENTITY_NAME, id<% if (primaryKey.type !== 'String') { %>.toString()<% } %>)).build())
);
<%_ } else { %>
.map(result -> ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, <%= enableTranslation %>, ENTITY_NAME, id<% if (primaryKey.type !== 'String') { %>.toString()<% } %>)).build()
.then(Mono.just(ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, <%= enableTranslation %>, ENTITY_NAME, id<% if (primaryKey.type !== 'String') { %>.toString()<% } %>)).build())
);
<%_ } _%>
<%_ } else { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public class UserResource {
.map(user -> {
try {
return ResponseEntity.created(new URI("/api/admin/users/" + user.getLogin()))
.headers(HeaderUtil.createAlert(applicationName, "userManagement.created", user.getLogin()))
.headers(HeaderUtil.createAlert(applicationName, <% if (enableTranslation) { %> "userManagement.created"<% } else { %> "A user is created with identifier " + user.getLogin()<% } %>, user.getLogin()))
.body(user);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -248,7 +248,7 @@ public class UserResource {
})
.switchIfEmpty(Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND)))
.map(user -> ResponseEntity.ok()
.headers(HeaderUtil.createAlert(applicationName, "userManagement.updated", userDTO.getLogin()))
.headers(HeaderUtil.createAlert(applicationName, <% if (enableTranslation) { %>"userManagement.updated"<% } else { %>"A user is updated with identifier " + userDTO.getLogin()<% } %>, userDTO.getLogin()))
.body(user)
);
<%_ } else { _%>
Expand Down Expand Up @@ -357,11 +357,10 @@ public class UserResource {
@DeleteMapping("/users/{login}")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
<%_ if (reactive) { _%>
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public Mono<ResponseEntity<Void>> deleteUser(@PathVariable @Pattern(regexp = Constants.LOGIN_REGEX) String login) {
log.debug("REST request to delete User: {}", login);
return userService.deleteUser(login)
.map(it -> ResponseEntity.noContent().headers(HeaderUtil.createAlert( applicationName, "userManagement.deleted", login)).build());
.then(Mono.just(ResponseEntity.noContent().headers(HeaderUtil.createAlert( applicationName, <% if (enableTranslation) { %> "userManagement.deleted"<% } else { %> "A user is deleted with identifier " + login<% } %>, login)).build()));
<%_ } else { _%>
public ResponseEntity<Void> deleteUser(@PathVariable @Pattern(regexp = Constants.LOGIN_REGEX) String login) {
log.debug("REST request to delete User: {}", login);
Expand Down