refactored user,role and region code
This commit is contained in:
@@ -111,14 +111,12 @@ public class RegionDao {
|
|||||||
}
|
}
|
||||||
public RegionResponseBean getRegionById(Long id) {
|
public RegionResponseBean getRegionById(Long id) {
|
||||||
log.info("Fetching region with ID: {}", id);
|
log.info("Fetching region with ID: {}", id);
|
||||||
RegionEntity regionEntity = regionRepository.findById(id)
|
RegionEntity regionEntity = validateRegion(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
|
||||||
return convertRegionEntityToRegionResponse(regionEntity);
|
return convertRegionEntityToRegionResponse(regionEntity);
|
||||||
}
|
}
|
||||||
public void deleteById(Long id) {
|
public void deleteById(Long id) {
|
||||||
log.info("Deleting region with ID: {}", id);
|
log.info("Deleting region with ID: {}", id);
|
||||||
regionRepository.findById(id)
|
validateRegion(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
|
||||||
regionRepository.deleteById(id);
|
regionRepository.deleteById(id);
|
||||||
log.info("Region deleted with ID: {}", id);
|
log.info("Region deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,15 +99,13 @@ public class RoleDao {
|
|||||||
}
|
}
|
||||||
public RoleResponseBean getRoleById(Long id) {
|
public RoleResponseBean getRoleById(Long id) {
|
||||||
log.info("Fetching role with ID: {}", id);
|
log.info("Fetching role with ID: {}", id);
|
||||||
RoleEntity roleEntity = roleRepository.findById(id)
|
RoleEntity roleEntity = validateRole(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
|
|
||||||
log.info("Role found: {}", roleEntity);
|
log.info("Role found: {}", roleEntity);
|
||||||
return convertRoleEntityToRoleResponse(roleEntity);
|
return convertRoleEntityToRoleResponse(roleEntity);
|
||||||
}
|
}
|
||||||
public void deleteById(Long id) {
|
public void deleteById(Long id) {
|
||||||
log.info("Deleting role with ID: {}", id);
|
log.info("Deleting role with ID: {}", id);
|
||||||
roleRepository.findById(id)
|
validateRole(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
|
|
||||||
roleRepository.deleteById(id);
|
roleRepository.deleteById(id);
|
||||||
log.info("Role deleted with ID: {}", id);
|
log.info("Role deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ public class UserDao {
|
|||||||
|
|
||||||
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
public UserResponseBean updateUser(Long userId, UpdateUserReq userReq) {
|
||||||
log.info("Updating user with ID: {}", userId);
|
log.info("Updating user with ID: {}", userId);
|
||||||
UserEntity userEntity = userRepository.findById(userId)
|
UserEntity userEntity=validateUser(userId);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
|
|
||||||
log.info("Current user details: {}", userEntity);
|
log.info("Current user details: {}", userEntity);
|
||||||
log.info("New user details: {}", userReq);
|
log.info("New user details: {}", userReq);
|
||||||
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
String newStatus = userReq.getStatus() != null ? userReq.getStatus().getValue() : null;
|
||||||
@@ -123,8 +122,7 @@ public class UserDao {
|
|||||||
|
|
||||||
public UserResponseBean getUserById(Long id) {
|
public UserResponseBean getUserById(Long id) {
|
||||||
log.info("Fetching user with ID: {}", id);
|
log.info("Fetching user with ID: {}", id);
|
||||||
UserEntity userEntity = userRepository.findById(id)
|
UserEntity userEntity=validateUser(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
|
||||||
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
// if (!UserStatusEnum.ACTIVE.getValue().equals(userEntity.getStatus())) {
|
||||||
// log.info("User with ID: {} is not active", id);
|
// log.info("User with ID: {} is not active", id);
|
||||||
// throw new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
// 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) {
|
public void deleteUser(Long id) {
|
||||||
log.info("Deleting user with ID: {}", id);
|
log.info("Deleting user with ID: {}", id);
|
||||||
userRepository.findById(id)
|
validateUser(id);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
|
||||||
userRepository.deleteById(id);
|
userRepository.deleteById(id);
|
||||||
log.info("User deleted with ID: {}", id);
|
log.info("User deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
@@ -150,7 +147,7 @@ public class UserDao {
|
|||||||
|
|
||||||
public UserEntity validateUser(Long userId) {
|
public UserEntity validateUser(Long userId) {
|
||||||
return userRepository.findById(userId)
|
return userRepository.findById(userId)
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
|
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
||||||
}
|
}
|
||||||
public String generateSecureToken() {
|
public String generateSecureToken() {
|
||||||
@@ -223,8 +220,7 @@ public class UserDao {
|
|||||||
|
|
||||||
public UserResponseBean updateUserStatus(Long userId, UserStatusEnum statusReq) {
|
public UserResponseBean updateUserStatus(Long userId, UserStatusEnum statusReq) {
|
||||||
log.info("Updating status for user with ID: {}", userId);
|
log.info("Updating status for user with ID: {}", userId);
|
||||||
UserEntity userEntity = userRepository.findById(userId)
|
UserEntity userEntity=validateUser(userId);
|
||||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG)));
|
|
||||||
userEntity.setStatus(statusReq.getValue());
|
userEntity.setStatus(statusReq.getValue());
|
||||||
userEntity = userRepository.save(userEntity);
|
userEntity = userRepository.save(userEntity);
|
||||||
log.info("User status updated to {} for user ID: {}", statusReq, userId);
|
log.info("User status updated to {} for user ID: {}", statusReq, userId);
|
||||||
|
|||||||
Reference in New Issue
Block a user