updated code for get all application api
This commit is contained in:
@@ -4,6 +4,7 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.*;
|
import net.gepafin.tendermanagement.entities.*;
|
||||||
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBean;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
|
||||||
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
|
||||||
@@ -114,26 +115,44 @@ public class ApplicationDao {
|
|||||||
log.info("Application deleted with ID: {}", id);
|
log.info("Application deleted with ID: {}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationResponse> getAllApplications(UserEntity userEntity,Long callId) {
|
public List<ApplicationResponse> getAllApplications(UserEntity userEntity, Long callId) {
|
||||||
log.info("Fetching all applications");
|
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
|
||||||
List<ApplicationResponse> applicationResponses=new ArrayList<>();
|
boolean isBeneficiary = RoleStatusEnum.ROLE_BENEFICIARY.equals(roleStatus);
|
||||||
if(callId!=null) {
|
|
||||||
|
log.info("Fetching applications for RoleType: {}", roleStatus);
|
||||||
|
List<ApplicationResponse> applicationResponses = new ArrayList<>();
|
||||||
|
|
||||||
|
if (callId != null) {
|
||||||
|
// Fetch based on callId and user if role is BENEFICIARY, otherwise fetch all for the call
|
||||||
|
log.info("Fetching applications for callId: {}", callId);
|
||||||
CallEntity call = callService.validateCall(callId);
|
CallEntity call = callService.validateCall(callId);
|
||||||
Optional<ApplicationEntity> applicationEntity1 = applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId());
|
|
||||||
if (applicationEntity1.isPresent()) {
|
// Use a single method to handle both conditions for consistency
|
||||||
ApplicationResponse responseBean = getApplicationResponse(applicationEntity1.get());
|
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
applicationResponses.add(responseBean);
|
? applicationRepository.findByUserIdAndCallIdAndIsDeletedFalse(userEntity.getId(), call.getId())
|
||||||
return applicationResponses;
|
.map(List::of) // Convert Optional<ApplicationEntity> to a List of one element
|
||||||
}
|
.orElse(List.of()) // If not present, return an empty list
|
||||||
}
|
: applicationRepository.findByCallIdAndIsDeletedFalse(call.getId());
|
||||||
List<ApplicationEntity> applicationEntities = applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId());
|
|
||||||
for(ApplicationEntity applicationEntity:applicationEntities){
|
applicationResponses = applicationEntities.stream()
|
||||||
ApplicationResponse responseBean = getApplicationResponse(applicationEntity);
|
.map(this::getApplicationResponse)
|
||||||
applicationResponses.add(responseBean);
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
|
} else {
|
||||||
|
// Fetch all applications for the user if BENEFICIARY, or fetch all applications in general
|
||||||
|
List<ApplicationEntity> applicationEntities = isBeneficiary
|
||||||
|
? applicationRepository.findByUserIdAndIsDeletedFalse(userEntity.getId())
|
||||||
|
: applicationRepository.findByIsDeletedFalse();
|
||||||
|
|
||||||
|
applicationResponses = applicationEntities.stream()
|
||||||
|
.map(this::getApplicationResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
return applicationResponses;
|
return applicationResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
private ApplicationResponse getApplicationResponse(ApplicationEntity applicationEntity) {
|
||||||
ApplicationResponse responseBean = new ApplicationResponse();
|
ApplicationResponse responseBean = new ApplicationResponse();
|
||||||
responseBean.setId(applicationEntity.getId());
|
responseBean.setId(applicationEntity.getId());
|
||||||
|
|||||||
@@ -19,4 +19,8 @@ public interface ApplicationRepository extends JpaRepository<ApplicationEntity,L
|
|||||||
|
|
||||||
@Query("SELECT a FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
@Query("SELECT a FROM ApplicationEntity a WHERE a.id = :id AND a.isDeleted = false")
|
||||||
Optional<ApplicationEntity> findById(@Param("id") Long id);
|
Optional<ApplicationEntity> findById(@Param("id") Long id);
|
||||||
|
|
||||||
|
public List<ApplicationEntity> findByCallIdAndIsDeletedFalse(Long callId);
|
||||||
|
|
||||||
|
public List<ApplicationEntity> findByIsDeletedFalse();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user