refactored user,role and region code
This commit is contained in:
@@ -65,8 +65,7 @@ public class UserDao {
|
||||
|
||||
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||
log.info("Updating user with ID: {}", userId);
|
||||
UserEntity userEntity = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
||||
UserEntity userEntity=validateUser(userId);
|
||||
log.info("Current user details: {}", userEntity);
|
||||
log.info("New user details: {}", userReq);
|
||||
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
||||
@@ -123,8 +122,7 @@ public class UserDao {
|
||||
|
||||
public UserResponseBean getUserById(Long id) {
|
||||
log.info("Fetching user with ID: {}", id);
|
||||
UserEntity userEntity = userRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
UserEntity userEntity=validateUser(id);
|
||||
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
||||
// log.info("User with ID: {} is not active", id);
|
||||
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||
@@ -135,8 +133,7 @@ public class UserDao {
|
||||
|
||||
public void deleteUser(Long id) {
|
||||
log.info("Deleting user with ID: {}", id);
|
||||
userRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
validateUser(id);
|
||||
userRepository.deleteById(id);
|
||||
log.info("User deleted with ID: {}", id);
|
||||
}
|
||||
@@ -150,7 +147,7 @@ public class UserDao {
|
||||
|
||||
public UserEntity validateUser(Long userId) {
|
||||
return userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
}
|
||||
public String generateSecureToken() {
|
||||
@@ -223,8 +220,7 @@ public class UserDao {
|
||||
|
||||
public UserResponseBean updateUserStatus(Long userId, UserStatusEnum statusReq) {
|
||||
log.info("Updating status for user with ID: {}", userId);
|
||||
UserEntity userEntity = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||
UserEntity userEntity=validateUser(userId);
|
||||
userEntity.setStatus(statusReq.getValue());
|
||||
userEntity = userRepository.save(userEntity);
|
||||
log.info("User status updated to {} for user ID: {}", statusReq, userId);
|
||||
|
||||
Reference in New Issue
Block a user