Step 10

To get our insertOrder() function working, we’ll need to add the code that inserts an order into the database. The following represents the code you’ll need to insert into our insertOrder() function:

Order order = fromJson((String) event.get("body"));
if (order == null) {
    response = new APIGatewayProxyResponseEvent()
            .withStatusCode(400);
} else {
    order = DAL.insertOrder(event, order);
    response = new APIGatewayProxyResponseEvent(
            .withStatusCode(200)
            .withBody(toJson(order));
}

This code extracts the order data from our incoming request. If the order is empty, we return with a status code of 400. Otherwise, we call our data access layer (DAL) to insert the order into the database and return a status code of 200. Insert this code into your insertOrder() function where the current comment appears and remove the comment.