Ejemplo n.º 1
0
    def handler(self, event, context):
        """
        Request handler method for fetch resource function.
        """
        if event is None or Constants.event_path_parameters() not in event:
            return response(http.HTTPStatus.BAD_REQUEST,
                            Constants.error_insufficient_parameters())

        if Constants.event_path_parameter_identifier() not in event[
                Constants.event_path_parameters()]:
            return response(http.HTTPStatus.BAD_REQUEST,
                            Constants.error_insufficient_parameters())

        _identifier = event[Constants.event_path_parameters()][
            Constants.event_path_parameter_identifier()]
        _http_method = event[Constants.event_http_method()]

        if _http_method == HttpConstants.http_method_get() and _identifier:
            _ddb_response = self.__retrieve_resource(_identifier)
            if len(_ddb_response[
                    Constants.ddb_response_attribute_name_items()]) == 0:
                return response(http.HTTPStatus.NOT_FOUND,
                                json.dumps(_ddb_response))
            return response(http.HTTPStatus.OK, json.dumps(_ddb_response))
        return response(http.HTTPStatus.BAD_REQUEST,
                        Constants.error_insufficient_parameters())