mirror of
https://github.com/jlengrand/dialogflow-fun.git
synced 2026-03-10 08:11:22 +00:00
Merge pull request #19 from jlengrand/users-lookup-table
Add simple user lookup to bank account
This commit is contained in:
@@ -4,7 +4,7 @@ import fr.lengrand.dialogflowfunapi.dialogflow.data.DialogFlowResponse;
|
||||
import fr.lengrand.dialogflowfunapi.dialogflow.data.DialogFlowWebHookRequest;
|
||||
import fr.lengrand.dialogflowfunapi.dialogflow.data.PaymentRequestDetails;
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.OpenBankClient;
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.paymentrequest.Account;
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.BankAccount;
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.paymentrequest.PaymentRequest;
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.transactions.Transaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,12 +28,16 @@ public class DialogFlowService {
|
||||
System.out.println(request.getQueryResult().getParameters().getUnitCurrency().getCurrency());
|
||||
System.out.println("/////////");
|
||||
|
||||
Optional<BankAccount> userAccount = UserAccountLookup.getBankAccountFromContact(request.getQueryResult().getParameters().getContact());
|
||||
|
||||
if (userAccount.isEmpty())
|
||||
return new DialogFlowResponse("Sorry, We have not found any bank account for " + request.getQueryResult().getParameters().getContact() + ". Cancelling.");
|
||||
|
||||
PaymentRequest paymentRequest = openBankClient.createPaymentRequest(UserAccountLookup.getCurrentUserAccount()
|
||||
, new PaymentRequestDetails(
|
||||
new Account("at02-1465--01",
|
||||
"bob_de_bouwer"),
|
||||
userAccount.get().toAccount(),
|
||||
request.getQueryResult().getParameters().getUnitCurrency(),
|
||||
"test at " + LocalDateTime.now())); // TODO : Add dynamic user lookup
|
||||
request.getQueryResult().getParameters().getContact() + " at " + LocalDateTime.now()));
|
||||
|
||||
return paymentRequest.getStatus().equalsIgnoreCase("completed") ?
|
||||
new DialogFlowResponse("Created a payment for a value of " + paymentRequest.getDetails().getValue().getAmount() + paymentRequest.getDetails().getValue().getCurrency() + " to " + request.getQueryResult().getParameters().getContact()) // TODO: Add reverse lookup
|
||||
|
||||
@@ -2,8 +2,24 @@ package fr.lengrand.dialogflowfunapi.dialogflow;
|
||||
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.BankAccount;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/*
|
||||
This is an oversimplified demo version of what it should look like. It does the job for our showcase though.
|
||||
*/
|
||||
public class UserAccountLookup {
|
||||
|
||||
private static Map<String, BankAccount> accountsLookup = Map.ofEntries(
|
||||
new AbstractMap.SimpleImmutableEntry<>("mum", new BankAccount("at02-1465--01", "bob_de_bouwer")),
|
||||
new AbstractMap.SimpleImmutableEntry<>("georges", new BankAccount("at02-1465--01", "424242")),
|
||||
new AbstractMap.SimpleImmutableEntry<>("bob", new BankAccount("at02-1465--01", "242424")),
|
||||
new AbstractMap.SimpleImmutableEntry<>("suzann", new BankAccount("at02-2080--01", "424242")),
|
||||
new AbstractMap.SimpleImmutableEntry<>("ellen", new BankAccount("at02-2080--01", "242424")),
|
||||
new AbstractMap.SimpleImmutableEntry<>("dad", new BankAccount("at02-0061--01", "424242"))
|
||||
);
|
||||
|
||||
private static final String ME_BANK_ID = "at02-1465--01";
|
||||
private static final String ME_USER_ID = "john_doe";
|
||||
|
||||
@@ -11,10 +27,9 @@ public class UserAccountLookup {
|
||||
return new BankAccount(ME_BANK_ID, ME_USER_ID);
|
||||
}
|
||||
|
||||
public BankAccount getBankAccountFromContact(String contact){
|
||||
return null;
|
||||
//TODO : Implement
|
||||
|
||||
public static Optional<BankAccount> getBankAccountFromContact(String contact){
|
||||
BankAccount bankAccount = accountsLookup.get(contact.toLowerCase().trim());
|
||||
return bankAccount == null? Optional.empty() : Optional.of(bankAccount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package fr.lengrand.dialogflowfunapi.openbankproject.data;
|
||||
|
||||
import fr.lengrand.dialogflowfunapi.openbankproject.data.paymentrequest.Account;
|
||||
|
||||
public class BankAccount {
|
||||
|
||||
private String userId;
|
||||
@@ -11,6 +13,10 @@ public class BankAccount {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Account toAccount(){
|
||||
return new Account(this.bankId, this.userId);
|
||||
}
|
||||
|
||||
public String getBankId() {
|
||||
return bankId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user