Add hubid for user

This commit is contained in:
harish
2024-09-25 17:37:34 +05:30
parent d7e2098b33
commit f2a206991f
22 changed files with 818 additions and 1 deletions

View File

@@ -6,11 +6,13 @@ import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.entities.UserHubEntity;
import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.repositories.UserHubRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.impl.AuthenticationService;
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
@@ -22,7 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@@ -39,7 +43,8 @@ public class UserDao {
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private UserHubRepository userHubRepository;
@Autowired
private RoleDao roleDao;
@@ -226,5 +231,25 @@ public class UserDao {
log.info("User status updated to {} for user ID: {}", statusReq, userId);
return convertUserEntityToUserResponse(userEntity);
}
public List<UserResponseBean> getUserByHubId(String hubId) {
log.info("Fetching users for hub ID: {}", hubId);
List<UserHubEntity> userHubMappings = userHubRepository.findByHubId(hubId);
List<UserResponseBean> userResponseBeans = new ArrayList<>();
for (UserHubEntity mapping : userHubMappings) {
UserEntity userEntity = validateUser(mapping.getUserId());
userResponseBeans.add(convertUserEntityToUserResponse(userEntity));
}
return userResponseBeans;
}
public UserResponseBean createUserByHubId(String hubId, UserReq userReq) {
log.info("Creating user for hub ID: {}", hubId);
UserResponseBean createdUser = createUser(userReq);
UserHubEntity mapping = new UserHubEntity();
mapping.setHubId(hubId);
mapping.setUserId(createdUser.getId());
userHubRepository.save(mapping);
log.info("User created and mapped to hub ID: {} with User ID: {}", hubId, createdUser.getId());
return createdUser;
}
}