added delete API for delegation
This commit is contained in:
@@ -156,7 +156,7 @@ public class CompanyDao {
|
||||
setIfUpdated(companyEntity::getContactName,companyEntity::setContactName,companyRequest.getContactName());
|
||||
setIfUpdated(companyEntity::getContactEmail,companyEntity::setContactEmail,companyRequest.getContactEmail());
|
||||
companyRepository.save(companyEntity);
|
||||
UserWithCompanyEntity userWithCompanyEntity = userWithCompanyRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId).orElse(null);
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
|
||||
companyRequest.getIsLegalRepresentant());
|
||||
userWithCompanyRepository.save(userWithCompanyEntity);
|
||||
@@ -169,7 +169,7 @@ public class CompanyDao {
|
||||
}
|
||||
|
||||
public CompanyResponse getCompany(UserEntity userEntity, Long companyId) {
|
||||
UserWithCompanyEntity userWithCompanyEntity = userWithCompanyRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId).orElse(null);
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||
return convertCompanyEntityToCompanyResponse(validateCompany(companyId), userWithCompanyEntity);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public class CompanyDao {
|
||||
List<Long> companyIds = userWithCompanyRepository.findCompanyIdByUserId(userEntity.getId());
|
||||
List<CompanyEntity> list = companyRepository.findByIdIn(companyIds);
|
||||
return list.stream().map(companyEntity->{
|
||||
UserWithCompanyEntity userWithCompanyEntity = userWithCompanyRepository.findByUserIdAndCompanyId(userEntity.getId(), companyEntity.getId()).orElse(null);
|
||||
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyEntity.getId());
|
||||
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||
}).toList();
|
||||
}
|
||||
@@ -193,5 +193,10 @@ public class CompanyDao {
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, companyId).orElseThrow(() -> new CustomValidationException(Status.UNAUTHORIZED,
|
||||
Translator.toLocale(GepafinConstant.UNAUTHORIZED)));
|
||||
}
|
||||
|
||||
public UserWithCompanyEntity getUserWithCompany(Long userId, Long compnayId) {
|
||||
return userWithCompanyRepository.findByUserIdAndCompanyId(userId, compnayId).orElseThrow(
|
||||
() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_COMPANY_RELATION_NOT_FOUND)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ public class DelegationDao {
|
||||
Map<String, String> placeholders = getDefaultPlaceholders();
|
||||
UserResponseBean user = userService.getUserById(userEntity.getId());
|
||||
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
|
||||
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
|
||||
return generateDocument(placeholders, documentEntity.getFileName());
|
||||
@@ -165,10 +166,11 @@ public class DelegationDao {
|
||||
placeholders.put(key, formatter.apply(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CompanyDelegationResponse uploadCompanyDelegation(UserEntity userEntity, Long companyId, MultipartFile file) {
|
||||
companyDao.validateCompany(companyId);
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
validateFileType(file);
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||
@@ -231,10 +233,24 @@ public class DelegationDao {
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
if(userCompanyDelegationEntity == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale("validation.error.file.invalidType"));
|
||||
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||
}
|
||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
||||
}
|
||||
|
||||
public void deleteCompanyDelegation(UserEntity userEntity, Long companyId) {
|
||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||
if(userCompanyDelegationEntity == null) {
|
||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||
}
|
||||
userCompanyDelegationEntity.setStatus(UserCompanyDelegationStatusEnum.INACTIVE.getValue());
|
||||
userCompanyDelegationRepository.save(userCompanyDelegationEntity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user