use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class UserController method changeUserInfo.
@PutMapping("/api/v1/user/{id}")
@PreAuthorize("hasAnyAuthority('MODERATOR', 'ADMIN')")
public ResponseEntity<?> changeUserInfo(@PathVariable Long id, @Valid @RequestBody UserChangeInfoDTO newUserInfo) {
User user = userService.getUserById(id);
String userRole = user.getRole().name();
boolean isModified = false;
if (Role.isCLIENT(userRole)) {
isModified = clientService.changeClientInfo(id, newUserInfo);
}
// for admin and moderator we can change only full name
String newFullName = newUserInfo.getFullName();
isModified = userService.changeFullName(id, newFullName);
log.debug("User with id " + id + " modified " + isModified);
return createModifyResponse(isModified);
}
Aggregations