gestion revu de code en utilisant uniquement les DTO
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
This commit is contained in:
@@ -8,6 +8,7 @@ import io.gmss.fiscad.exceptions.*;
|
||||
import io.gmss.fiscad.interfaces.user.UserService;
|
||||
import io.gmss.fiscad.paylaods.ApiResponse;
|
||||
import io.gmss.fiscad.paylaods.Login;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb;
|
||||
import io.gmss.fiscad.security.CurrentUser;
|
||||
import io.gmss.fiscad.security.UserPrincipal;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -40,12 +42,11 @@ public class UserController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated User user) {
|
||||
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated UserPaylaodWeb userPaylaodWeb) {
|
||||
try {
|
||||
user.setUsername(user.getEmail());
|
||||
user = userService.createUser(user, true);
|
||||
userPaylaodWeb = userService.createUser(userPaylaodWeb);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, user, "Utilisateur créé avec succès"),
|
||||
new ApiResponse<>(true, userPaylaodWeb, "Utilisateur créé avec succès"),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -91,9 +92,9 @@ public class UserController {
|
||||
@PostMapping("/reset-password")
|
||||
public ResponseEntity<?> resetUserPassword(@RequestBody @Valid @Validated Login login) {
|
||||
try {
|
||||
User user = userService.resetPassword(login.getUsername(), login.getPassword());
|
||||
UserPaylaodWeb userPaylaodWeb= userService.resetPassword(login.getUsername(), login.getPassword());
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, user, "Votre mot de passe à été réinitialisée avec succès."),
|
||||
new ApiResponse<>(true, userPaylaodWeb, "Votre mot de passe à été réinitialisée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -138,10 +139,10 @@ public class UserController {
|
||||
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody User user) {
|
||||
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody UserPaylaodWeb userPaylaodWeb) {
|
||||
try {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, userService.updateUser(id, user), "Utilisateur modifié avec succès."),
|
||||
new ApiResponse<>(true, userService.updateUser(id, userPaylaodWeb), "Utilisateur modifié avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -343,26 +344,5 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/all-by-role/{userrole}")
|
||||
public ResponseEntity<?> getUserByUserRole(@PathVariable UserRole userrole) {
|
||||
try {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, userService.getUserByProfil(userrole), "Users found."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
||||
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
||||
FileStorageException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
||||
} catch (NullPointerException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user