def get(self): """ Return a list of all String values This endpoint will create a String based the data in the body that is posted """ strings = String.all() results = [string.serialize() for string in strings] return results, status.HTTP_200_OK
def get(self, key): """ Return the String value identified by key This endpoint will return a String based on it's key """ app.logger.info("Request to Retrieve a string with key [%s]", key) string = String.find(key) if not string: raise NotFound("String with key '{}' was not found.".format(key)) return string.serialize(), status.HTTP_200_OK
def get(self): """ Return the String value identified by key This endpoint will return a String based on it's key """ # check_content_type('application/json') search_term = api.payload.get('search_term', None) strings = String.search(search_term) results = [string.serialize() for string in strings] return results, status.HTTP_200_OK
def delete(self, key): """ Delete the String identified by key This endpoint will delete a String based the key specified in the path """ app.logger.info('Request to Delete a string with key [%s]', key) string = String.find(key) if string: string.delete() return 'String deleted', status.HTTP_204_NO_CONTENT
def post(self): """ Instantiate or overwrite a String identified by key with value value This endpoint will create a String based the data in the body that is posted """ check_content_type('application/json') string = String() app.logger.info('Payload = %s', api.payload) string.deserialize(api.payload) string.save() app.logger.info('String with new key [%s] saved!', string.key) # location_url = api.url_for(PetResource, key=string.key, _external=True) # return string.serialize(), status.HTTP_201_CREATED, {'Location': location_url} return string.serialize(), status.HTTP_201_CREATED
def put(self, key): """ Update the value of the String identified by key This endpoint will update a String based the body that is posted """ app.logger.info('Request to Update a string with key [%s]', key) check_content_type('application/json') string = String.find(key) if not string: # api.abort(404, "String with key '{}' was not found.".format(key)) raise NotFound('String with key [{}] was not found.'.format(key)) # data = request.get_json() data = api.payload app.logger.info(data) string.deserialize(data) string.key = key string.save() return string.serialize(), status.HTTP_200_OK
def strings_reset(): """ Removes all string from the database """ String.remove_all() return make_response('', status.HTTP_204_NO_CONTENT)