fixed a non-404 responce in the case when the customer is not found

This commit is contained in:
dartpopikyardo
2016-09-27 16:08:11 +03:00
parent 7260376b17
commit 4b74d2c1f1
5 changed files with 107 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.commonauth;
import net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside.common.QuerySideCustomer;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.support.DataAccessUtils;
/**
@@ -14,10 +15,18 @@ public class CustomerAuthService {
}
public QuerySideCustomer findByEmail(String email) {
return DataAccessUtils.uniqueResult(customerAuthRepository.findByEmail(email));
QuerySideCustomer result = DataAccessUtils.uniqueResult(customerAuthRepository.findByEmail(email));
if (result==null)
throw new EmptyResultDataAccessException(1);
return result;
}
public QuerySideCustomer findByEmailAndPassword(String email, String password) {
return DataAccessUtils.uniqueResult(customerAuthRepository.findByEmailAndPassword(email, password));
QuerySideCustomer result = DataAccessUtils.uniqueResult(customerAuthRepository.findByEmailAndPassword(email, password));
if (result==null)
throw new EmptyResultDataAccessException(1);
return result;
}
}