|
|
|
|
@ -2,6 +2,7 @@ package com.mfsys.aconnect.usermanagement.service;
|
|
|
|
|
|
|
|
|
|
import com.mfsys.common.configuration.service.PasswordEncryptionService;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.dto.UserDTOs;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.dto.PermissionDTO;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.model.User;
|
|
|
|
|
import com.mfsys.aconnect.usermanagement.repository.UserRepository;
|
|
|
|
|
import jakarta.persistence.EntityNotFoundException;
|
|
|
|
|
@ -87,4 +88,45 @@ public class UserService {
|
|
|
|
|
response.setUpdatedAt(user.getUpdatedAt());
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public UserDTOs.UserResponse saveUserPermissions(PermissionDTO permissionDTO) {
|
|
|
|
|
User user = userRepository.findById(permissionDTO.getUserId())
|
|
|
|
|
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + permissionDTO.getUserId()));
|
|
|
|
|
|
|
|
|
|
// Convert list of permissions to comma-separated string
|
|
|
|
|
String permissions = String.join(",", permissionDTO.getPermissions());
|
|
|
|
|
user.setPermissions(permissions);
|
|
|
|
|
User updatedUser = userRepository.save(user);
|
|
|
|
|
|
|
|
|
|
return mapToResponseDTO(updatedUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PermissionDTO getUserPermissions(String userId) {
|
|
|
|
|
User user = userRepository.findById(userId)
|
|
|
|
|
.orElseThrow(() -> new EntityNotFoundException("User not found with ID: " + userId));
|
|
|
|
|
|
|
|
|
|
PermissionDTO dto = new PermissionDTO();
|
|
|
|
|
dto.setUserId(userId);
|
|
|
|
|
if (user.getPermissions() != null && !user.getPermissions().isEmpty()) {
|
|
|
|
|
dto.setPermissions(java.util.Arrays.asList(user.getPermissions().split(",")));
|
|
|
|
|
}
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public UserDTOs.UserResponse updateUserPermissions(PermissionDTO permissionDTO) {
|
|
|
|
|
|
|
|
|
|
User user = userRepository.findById(permissionDTO.getUserId())
|
|
|
|
|
.orElseThrow(() ->
|
|
|
|
|
new EntityNotFoundException("User not found with ID: " + permissionDTO.getUserId())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
String permissions = String.join(",", permissionDTO.getPermissions());
|
|
|
|
|
user.setPermissions(permissions);
|
|
|
|
|
|
|
|
|
|
User updatedUser = userRepository.save(user);
|
|
|
|
|
return mapToResponseDTO(updatedUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|