91.1. Test delete (#10)

This commit is contained in:
Art
2021-09-11 10:16:59 +03:00
parent 1d058a367c
commit 26c287fd29
5 changed files with 102 additions and 36 deletions

View File

@ -12,6 +12,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@ -96,13 +97,14 @@ public class UserResource {
}
@DeleteMapping("{id}")
@PreAuthorize("hasAuthority('user:delete')")
public HttpResponse deleteUser(@PathVariable long id) {
userService.deleteUser(id);
return HttpResponse.builder()
.httpStatusCode(OK.value())
.httpStatus(OK)
.reason(OK.getReasonPhrase())
.message("User deleted successfully")
.message("User deleted successfully".toUpperCase())
.build();
}

View File

@ -7,6 +7,7 @@ import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.Email
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailNotFoundException;
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.UserNotFoundException;
import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.UsernameExistsException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
@ -70,6 +71,13 @@ public class ExceptionHandling {
return createHttpResponse(BAD_REQUEST, exception.getMessage());
}
@ExceptionHandler({
EmptyResultDataAccessException.class
})
public ResponseEntity<HttpResponse> emptyResultDataAccessExceptionHandler(EmptyResultDataAccessException exception) {
return createHttpResponse(BAD_REQUEST, "" + exception.getMessage());
}
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<HttpResponse> methodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
HttpMethod supportedMethod = Objects.requireNonNull(exception.getSupportedHttpMethods()).iterator().next();