Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
edit customer fix - check for existing customer was happening for edi…
Browse files Browse the repository at this point in the history
…t customer also
  • Loading branch information
matallen committed Aug 14, 2018
1 parent 1a0b824 commit 03baea1
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1089,19 +1089,20 @@ public ResponseEntity<String> createOrUpdateCustomer(String custId, CustomerType
if (custId==null){
myCust=new Customer();
myCust.setId(UUID.randomUUID().toString());

// check customer doesnt already exist with the same name
Customer example=new Customer();
example.setName(body.getCustomerName());
long count=custRepo.count(Example.of(example));
if (count>0){
log.error("Customer already exists with name {}", body.getCustomerName());
return new ResponseEntity<>("Customer already exists with name "+body.getCustomerName(), HttpStatus.BAD_REQUEST);
}

}else{
myCust=custRepo.findOne(custId);
}

// check customer doesnt already exist with the same name
Customer example=new Customer();
example.setName(body.getCustomerName());
long count=custRepo.count(Example.of(example));
if (count>0){
log.error("Customer already exists with name {}", body.getCustomerName());
return new ResponseEntity<>("Customer already exists with name "+body.getCustomerName(), HttpStatus.BAD_REQUEST);
}

myCust.setName(body.getCustomerName());
myCust.setDescription(body.getCustomerDescription());
myCust.setVertical(body.getCustomerVertical());
Expand Down

0 comments on commit 03baea1

Please sign in to comment.