-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsuranceService.bal
56 lines (45 loc) · 1.14 KB
/
InsuranceService.bal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import ballerina/http;
service /insurance on new http:Listener(9098) {
@http:ResourceConfig {
consumes: ["application/json"]
}
resource function post rate(@http:Payload json customer )
returns json | error {
json loanIDAsJson = check customer.event.loanApplicationID;
string loanID = loanIDAsJson.toString();
int creditScore = getCreditScore(loanID);
float insuranceRate = getInsuranceRate(creditScore);
json payload = {
"loanApplicationID" : check customer.event.loanApplicationID,
"insuranceRate" : insuranceRate
};
return payload;
}
}
function getCreditScore(string loanID) returns int{
int creditScore = 0;
// Ideally retrieve a given customer's creditscore from shared storage/service
if(loanID == "1111"){
creditScore = 620;
}
if(loanID == "2222"){
creditScore = 700;
}
if(loanID == "3333"){
creditScore =660;
}
return creditScore ;
}
function getInsuranceRate(int creditScore) returns float{
float insuranceRate = 0.0;
if(creditScore == 620){
insuranceRate = 1.2;
}
if(creditScore == 700){
insuranceRate = 0.6;
}
if(creditScore == 660){
insuranceRate = 1;
}
return insuranceRate;
}