def store()

in microservices/message_board/main.py [0:0]


def store():
    json_data = request.get_json()
    name, message = None, None
    if 'name' in json_data.keys():
        name = json_data['name']
    if 'message' in json_data.keys():
        message = json_data['message']

    if name is None or message is None:
        resp = {'message': 'name and message properties are required.'}
        return resp, 500

    resp = {
        'name': name,
        'message': message,
        'timestamp': datetime.datetime.utcnow()
    }
    incomplete_key = ds_client.key('Message')   # Create a new key for kind 'Message'.
    message_entity = datastore.Entity(key=incomplete_key) # Create a new entity.
    message_entity.update(resp)                 # Update the entity's contents.
    ds_client.put(message_entity)               # Store the entity in Datastore.

    return resp, 200