Created
February 17, 2020 17:01
-
-
Save nuwanbando/baa4999989615d659626e6b58baf5e47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bookAirline(http:Caller caller, map<json> outReqPayload, json | error airlinePreference, http:Response outResponse) returns error? { | |
// Reserve airline ticket for the user by calling Airline reservation service | |
// construct the payload | |
map<json> outReqPayloadAirline = outReqPayload.clone(); | |
outReqPayloadAirline["Preference"] = <json>airlinePreference; | |
// Send a post request to airlineReservationService with appropriate payload and get response | |
http:Response inResAirline = check airlineReservationEP->post("/reserve", <@untainted>outReqPayloadAirline); | |
// Get the reservation status | |
var airlineResPayload = check <@untainted>inResAirline.getJsonPayload(); | |
string airlineStatus = airlineResPayload.Status.toString(); | |
// If reservation status is negative, send a failure response to user | |
if (airlineStatus != "Success") { | |
outResponse.setJsonPayload({ | |
"Message": "Failed to reserve airline! " + | |
"Provide a valid 'Preference' for 'Airline' and try again" | |
}); | |
var result = caller->respond(outResponse); | |
if (result is error) { | |
log:printError(result.reason(), err = result); | |
} | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment