예제 #1
0
    def put_Point(self, putPointInput: 'PutPointInput'):
        """
        The dict in Item put_item call, should contains a dict with string as a key and a string as a value: {"N": "123"}
        """
        geohash = S2Manager().generateGeohash(putPointInput.GeoPoint)
        hashKey = S2Manager().generateHashKey(geohash,
                                              self.config.hashKeyLength)
        response = ""
        params = putPointInput.ExtraFields.copy()

        params['TableName'] = self.config.tableName

        if ('Item' not in putPointInput.ExtraFields.keys()):
            params['Item'] = {}

        params['Item'][self.config.hashKeyAttributeName] = {"N": str(hashKey)}
        params['Item'][self.config.rangeKeyAttributeName] = {
            "S": putPointInput.RangeKeyValue
        }
        params['Item'][self.config.geohashAttributeName] = {'N': str(geohash)}
        params['Item'][self.config.geoJsonAttributeName] = {
            "S":
            "{},{}".format(putPointInput.GeoPoint.latitude,
                           putPointInput.GeoPoint.longitude)
        }

        try:
            response = self.config.dynamoDBClient.put_item(**params)
        except Exception as e:
            print("The following error occured during the item insertion :{}".
                  format(e))
            response = "Error"
        return response
예제 #2
0
    def update_Point(self, UpdateItemInput: 'UpdateItemInput'):
        """
        The dict in Item Update call, should contains a dict with string as a key and a string as a value: {"N": "123"}
        """
        geohash = S2Manager().generateGeohash(UpdateItemInput.GeoPoint)
        hashKey = S2Manager().generateHashKey(geohash,
                                              self.config.hashKeyLength)
        response = ""
        params = UpdateItemInput.ExtraFields.copy()

        params['TableName'] = self.config.tableName

        if ('Key' not in UpdateItemInput.ExtraFields.keys()):
            params['Key'] = {}

        params['Key'][self.config.hashKeyAttributeName] = {"N": str(hashKey)}
        params['Key'][self.config.rangeKeyAttributeName] = {
            "S": UpdateItemInput.RangeKeyValue
        }

        #TODO Geohash and geoJson cannot be updated. For now no control over that need to be added
        try:
            response = self.config.dynamoDBClient.update_item(**params)
        except Exception as e:
            print("The following error occured during the item update :{}".
                  format(e))
            response = "Error"
        return response
예제 #3
0
    def delete_Point(self, DeleteItemInput: 'DeleteItemInput'):
        """
        The dict in Item Update call, should contains a dict with string as a key and a string as a value: {"N": "123"}
        """
        geohash = S2Manager().generateGeohash(DeleteItemInput.GeoPoint)
        hashKey = S2Manager().generateHashKey(geohash,
                                              self.config.hashKeyLength)
        response = ""
        params = DeleteItemInput.ExtraFields.copy()

        params['TableName'] = self.config.tableName

        if ('Key' not in DeleteItemInput.ExtraFields.keys()):
            params['Key'] = {}

        params['Key'][self.config.hashKeyAttributeName] = {"N": str(hashKey)}
        params['Key'][self.config.rangeKeyAttributeName] = {
            "S": DeleteItemInput.RangeKeyValue
        }
        try:
            response = self.config.dynamoDBClient.delete_item(**params)
        except Exception as e:
            print("The following error occured during the item delete :{}".
                  format(e))
            response = "Error"
        return response
 def get_Point(self, getPointInput: 'GetPointInput'):
     """
     The dict in Key get_item call, should contains a dict with string as a key and a string as a value: {"N": "123"}
     """
     geohash = S2Manager().generateGeohash(getPointInput.GeoPoint)
     hashKey = S2Manager().generateHashKey(geohash, self.config.hashKeyLength)
     response = ""
     try:
         response = self.config.dynamoDBClient.get_item(
             TableName=self.config.tableName,
             Key={
                 self.config.hashKeyAttributeName: {"N": str(hashKey)},
                 self.config.rangeKeyAttributeName: {
                     "S": getPointInput.RangeKeyValue}
             }
         )
     except Exception as e:
         print("The following error occured during the item retrieval :{}".format(e))
         response = "Error"
     return response