in software/products/src/main/java/software/amazonaws/example/product/entrypoints/ApiGatewayDeleteProductRequestHandler.java [25:52]
public APIGatewayV2HTTPResponse handleRequest(APIGatewayV2HTTPEvent event, Context context) {
String id = event.getPathParameters().get("id");
if (id == null) {
logger.warn("Missing 'id' parameter in path");
return APIGatewayV2HTTPResponse.builder()
.withStatusCode(400)
.withHeaders(Map.of(CONTENT_TYPE, "application/json"))
.withBody("{ \"message\": \"Missing 'id' parameter in path\" }")
.build();
}
try {
productStore.deleteProduct(id);
} catch (Exception e) {
logger.error(e.getMessage());
return APIGatewayV2HTTPResponse.builder()
.withStatusCode(500)
.withHeaders(Map.of(CONTENT_TYPE, "application/json"))
.withBody("{\"message\": \"Failed to delete product\"}")
.build();
}
return APIGatewayV2HTTPResponse.builder()
.withStatusCode(200)
.withHeaders(Map.of(CONTENT_TYPE, "application/json"))
.withBody("{\"message\": \"Product deleted\"}")
.build();
}