added delete API for delegation
This commit is contained in:
@@ -195,5 +195,8 @@ public class GepafinConstant {
|
|||||||
public static final String CALL_NOT_STARTED_YET = "call.not.started.yet";
|
public static final String CALL_NOT_STARTED_YET = "call.not.started.yet";
|
||||||
public static final String CALL_ALREADY_ENDED = "call.already.ended";
|
public static final String CALL_ALREADY_ENDED = "call.already.ended";
|
||||||
public static final String APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "application.status.updated.successfully";
|
public static final String APPLICATION_STATUS_UPDATED_SUCCESSFULLY = "application.status.updated.successfully";
|
||||||
|
public static final String DELEGATION_NOT_FOUND = "delegation.not.found";
|
||||||
|
public static final String USER_COMPANY_RELATION_NOT_FOUND = "user.company.relation.not.found";
|
||||||
|
public static final String DELEGATION_DELETE_SUCCESS = "delegation.delete.success";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class CompanyDao {
|
|||||||
setIfUpdated(companyEntity::getContactName,companyEntity::setContactName,companyRequest.getContactName());
|
setIfUpdated(companyEntity::getContactName,companyEntity::setContactName,companyRequest.getContactName());
|
||||||
setIfUpdated(companyEntity::getContactEmail,companyEntity::setContactEmail,companyRequest.getContactEmail());
|
setIfUpdated(companyEntity::getContactEmail,companyEntity::setContactEmail,companyRequest.getContactEmail());
|
||||||
companyRepository.save(companyEntity);
|
companyRepository.save(companyEntity);
|
||||||
UserWithCompanyEntity userWithCompanyEntity = userWithCompanyRepository.findByUserIdAndCompanyId(userEntity.getId(), companyId).orElse(null);
|
UserWithCompanyEntity userWithCompanyEntity = getUserWithCompany(userEntity.getId(), companyId);
|
||||||
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
|
Utils.setIfUpdated(userWithCompanyEntity::getIsLegalRepresentant, userWithCompanyEntity::setIsLegalRepresentant,
|
||||||
companyRequest.getIsLegalRepresentant());
|
companyRequest.getIsLegalRepresentant());
|
||||||
userWithCompanyRepository.save(userWithCompanyEntity);
|
userWithCompanyRepository.save(userWithCompanyEntity);
|
||||||
@@ -169,7 +169,7 @@ public class CompanyDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompanyResponse getCompany(UserEntity userEntity, Long companyId) {
|
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);
|
return convertCompanyEntityToCompanyResponse(validateCompany(companyId), userWithCompanyEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ public class CompanyDao {
|
|||||||
List<Long> companyIds = userWithCompanyRepository.findCompanyIdByUserId(userEntity.getId());
|
List<Long> companyIds = userWithCompanyRepository.findCompanyIdByUserId(userEntity.getId());
|
||||||
List<CompanyEntity> list = companyRepository.findByIdIn(companyIds);
|
List<CompanyEntity> list = companyRepository.findByIdIn(companyIds);
|
||||||
return list.stream().map(companyEntity->{
|
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);
|
return convertCompanyEntityToCompanyResponse(companyEntity, userWithCompanyEntity);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
@@ -194,4 +194,9 @@ public class CompanyDao {
|
|||||||
Translator.toLocale(GepafinConstant.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();
|
Map<String, String> placeholders = getDefaultPlaceholders();
|
||||||
UserResponseBean user = userService.getUserById(userEntity.getId());
|
UserResponseBean user = userService.getUserById(userEntity.getId());
|
||||||
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
|
CompanyEntity companyEntity = companyDao.validateCompany(companyId);
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
|
updatePlaceholdersForDelegation(user, companyEntity, placeholders, companyDelegationRequest);
|
||||||
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
|
DocumentEntity documentEntity = documentRepository.findBySource(GepafinConstant.DELEGATION_TEMPLATE).get(0);
|
||||||
return generateDocument(placeholders, documentEntity.getFileName());
|
return generateDocument(placeholders, documentEntity.getFileName());
|
||||||
@@ -169,6 +170,7 @@ public class DelegationDao {
|
|||||||
|
|
||||||
public CompanyDelegationResponse uploadCompanyDelegation(UserEntity userEntity, Long companyId, MultipartFile file) {
|
public CompanyDelegationResponse uploadCompanyDelegation(UserEntity userEntity, Long companyId, MultipartFile file) {
|
||||||
companyDao.validateCompany(companyId);
|
companyDao.validateCompany(companyId);
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
validateFileType(file);
|
validateFileType(file);
|
||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||||
@@ -231,10 +233,24 @@ public class DelegationDao {
|
|||||||
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
UserCompanyDelegationEntity userCompanyDelegationEntity = userCompanyDelegationRepository
|
||||||
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
.findByUserIdAndCompanyIdAndStatus(userEntity.getId(), companyId,
|
||||||
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
UserCompanyDelegationStatusEnum.ACTIVE.getValue());
|
||||||
|
companyDao.getUserWithCompany(userEntity.getId(), companyId);
|
||||||
if(userCompanyDelegationEntity == null) {
|
if(userCompanyDelegationEntity == null) {
|
||||||
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
throw new ResourceNotFoundException(Status.NOT_FOUND,
|
||||||
Translator.toLocale("validation.error.file.invalidType"));
|
Translator.toLocale(GepafinConstant.DELEGATION_NOT_FOUND));
|
||||||
}
|
}
|
||||||
return convertUserCompanyDelegationToCompanyDelegationResponse(userCompanyDelegationEntity);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,6 @@ public interface CompanyService {
|
|||||||
|
|
||||||
CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId);
|
CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId);
|
||||||
|
|
||||||
|
void deleteCompanyDelegation(HttpServletRequest request, Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,4 +108,10 @@ public class CompanyServiceImpl implements CompanyService {
|
|||||||
UserEntity userEntity =validator.validateUser(request);
|
UserEntity userEntity =validator.validateUser(request);
|
||||||
return delegationDao.getCompanyDelegation(userEntity, companyId);
|
return delegationDao.getCompanyDelegation(userEntity, companyId);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteCompanyDelegation(HttpServletRequest request, Long companyId) {
|
||||||
|
UserEntity userEntity =validator.validateUser(request);
|
||||||
|
delegationDao.deleteCompanyDelegation(userEntity, companyId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,4 +132,15 @@ public interface CompanyApi {
|
|||||||
ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
||||||
@Parameter(description = "The company id", required = true) @PathVariable("companyId") Long companyId);
|
@Parameter(description = "The company id", required = true) @PathVariable("companyId") Long companyId);
|
||||||
|
|
||||||
|
@Operation(summary = "Api to delete company delegation", responses = { @ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||||
|
@DeleteMapping(value = "{companyId}/delegation", produces = { "application/json" })
|
||||||
|
ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request,
|
||||||
|
@Parameter(description = "The company id", required = true) @PathVariable("companyId") Long companyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,17 +108,24 @@ public class CompanyApiController implements CompanyApi{
|
|||||||
MultipartFile file) {
|
MultipartFile file) {
|
||||||
log.info("upload company delegation with companyId: {}", companyId);
|
log.info("upload company delegation with companyId: {}", companyId);
|
||||||
CompanyDelegationResponse companyDelegationResponse = companyService.uploadCompanyDelegation(request, companyId, file);
|
CompanyDelegationResponse companyDelegationResponse = companyService.uploadCompanyDelegation(request, companyId, file);
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.CREATED)
|
||||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FILE_UPLOAD_SUCCESS)));
|
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FILE_UPLOAD_SUCCESS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
public ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
||||||
Long companyId) {
|
Long companyId) {
|
||||||
|
|
||||||
log.info("get company delegation with companyId: {}", companyId);
|
log.info("get company delegation with companyId: {}", companyId);
|
||||||
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId);
|
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId);
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FETCH_SUCCESS)));
|
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FETCH_SUCCESS)));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request,
|
||||||
|
Long companyId) {
|
||||||
|
log.info("delete company delegation with companyId: {}", companyId);
|
||||||
|
companyService.deleteCompanyDelegation(request, companyId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_DELETE_SUCCESS)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,3 +220,8 @@ call.not.started.yet = The call has not started yet. Please wait until the speci
|
|||||||
call.already.ended = The call has already ended. You cannot submit the application after the deadline.
|
call.already.ended = The call has already ended. You cannot submit the application after the deadline.
|
||||||
status.updated.successfully=Status updated successfully.
|
status.updated.successfully=Status updated successfully.
|
||||||
application.status.updated.successfully = Application status updated successfully.
|
application.status.updated.successfully = Application status updated successfully.
|
||||||
|
delegation.not.found=Delegation not found.
|
||||||
|
user.company.relation.not.found=User with the specified company relation not found.
|
||||||
|
delegation.delete.success=Delegation deleted successfully.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -215,3 +215,8 @@ call.not.started.yet = La chiamata non <20> ancora iniziata. Attendere fino alla
|
|||||||
call.already.ended = La chiamata <20> gi<67> terminata. Non <20> possibile inviare l'applicazione dopo la scadenza.
|
call.already.ended = La chiamata <20> gi<67> terminata. Non <20> possibile inviare l'applicazione dopo la scadenza.
|
||||||
status.updated.successfully=Stato aggiornato con successo.
|
status.updated.successfully=Stato aggiornato con successo.
|
||||||
application.status.updated.successfully = Stato dell'applicazione aggiornato con successo.
|
application.status.updated.successfully = Stato dell'applicazione aggiornato con successo.
|
||||||
|
delegation.not.found=Delega non trovata.
|
||||||
|
user.company.relation.not.found=Relazione utente con l'azienda specificata non trovata.
|
||||||
|
delegation.delete.success=Delega eliminata con successo.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user