public APIGatewayV2HTTPResponse handleRequest()

in software/products/src/main/java/software/amazonaws/example/product/entrypoints/ApiGatewayGetAllProductRequestHandler.java [37:62]


    public APIGatewayV2HTTPResponse handleRequest(APIGatewayV2HTTPEvent event, Context context) {
        Products products;
        try {
            products = productStore.getAllProduct();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return APIGatewayV2HTTPResponse.builder()
                    .withStatusCode(500)
                    .withHeaders(Map.of(CONTENT_TYPE, "application/json"))
                    .withBody("{\"message\": \"Failed to get products\"}")
                    .build();
        }

        try {
            return APIGatewayV2HTTPResponse.builder()
                    .withStatusCode(200)
                    .withHeaders(Map.of(CONTENT_TYPE, "application/json"))
                    .withBody(objectMapper.writeValueAsString(products))
                    .build();
        } catch (JsonProcessingException e) {
            logger.error(e.getMessage(), e);
            return APIGatewayV2HTTPResponse.builder()
                    .withStatusCode(500)
                    .build();
        }
    }