policy/src/main/java/com/stackroute.pie/service/PolicyServiceImpl.java
//Method for deleting the insuredName from the policy
Method for deleting the insuredName from the policy
Method for deleting the insuredName from the policy
@Override
    public Policy deleteInsured(String insurerName, String policyName, String insuredName)
            throws InsurerNotFoundException,PolicyNotFoundException{
        if(policyRepository.existsByInsurerName(insurerName)) {
            if(policyRepository.existsByPolicyNameAndInsurerName(policyName,insurerName)) {
                Policy policy = policyRepository.findByUniqueId(insurerName+policyName).get();
                List<String> insuredList = policy.getInsuredList();
                insuredList.remove(insuredName);
                policy.setInsuredList(insuredList);
                policyRepository.save(policy);
                return policyRepository.findByInsurerNameAndPolicyName(insurerName,policyName).get();
            }
            else {
                throw new PolicyNotFoundException();
            }
        }
        else {
            throw new InsurerNotFoundException();
        }
    }
@ Override public Policy deleteInsured ( String insurerName , String policyName , String insuredName ) throws InsurerNotFoundException , PolicyNotFoundException { if ( policyRepository . existsByInsurerName ( insurerName ) ) { if ( policyRepository . existsByPolicyNameAndInsurerName ( policyName , insurerName ) ) { Policy policy = policyRepository . findByUniqueId ( insurerName + policyName ) . get ( ) ; List < String > insuredList = policy . getInsuredList ( ) ; insuredList . remove ( insuredName ) ; policy . setInsuredList ( insuredList ) ; policyRepository . save ( policy ) ; return policyRepository . findByInsurerNameAndPolicyName ( insurerName , policyName ) . get ( ) ; } else { throw new PolicyNotFoundException ( ) ; } } else { throw new InsurerNotFoundException ( ) ; } }
Method for deleting the insuredName from the policy
Method for deleting the insuredName from the policy