def get(self): """ Return a list of all list of Strings This endpoint will return all the list of strings in the database """ lists = List.all() results = [list.serialize() for list in lists] return results, status.HTTP_200_OK
def put(self): """ Remove the last element in the List identified by key, and return that element. This endpoint will update a List based the body that is posted """ check_content_type('application/json') app.logger.info('Payload = %s', api.payload) item = List.pop(api.payload) return item, status.HTTP_200_OK
def get(self, key): """ Return the List value identified by key This endpoint will return a List based on it's key """ app.logger.info("Request to Retrieve a list with key [%s]", key) list = List.find(key) if not list: raise NotFound("List with key '{}' was not found.".format(key)) return list.serialize(), status.HTTP_200_OK
def post(self): """ Append a String value to the end of the List identified by key This endpoint will create a List based the data in the body that is posted """ check_content_type('application/json') app.logger.info('Payload = %s', api.payload) list = List.append(api.payload) app.logger.info('List with new key [%s] saved!', list.key) return list.serialize(), status.HTTP_201_CREATED
def delete(self, key): """ Delete the List identified by key This endpoint will delete a List based the key specified in the path """ app.logger.info('Request to Delete a list with key [%s]', key) list = List.find(key) if list: list.delete() return 'List deleted', status.HTTP_204_NO_CONTENT
def post(self): """ Instantiate or overwrite a List identified by key with value value This endpoint will create a List based the data in the body that is posted """ check_content_type('application/json') list = List() app.logger.info('Payload = %s', api.payload) list.deserialize(api.payload) list.save() app.logger.info('List with new key [%s] saved!', list.key) return list.serialize(), status.HTTP_201_CREATED
def put(self, key): """ Update the List identified by key This endpoint will update a List based the body that is posted """ app.logger.info('Request to Update a list with key [%s]', key) check_content_type('application/json') list = List.find(key) if not list: # api.abort(404, "List with key '{}' was not found.".format(key)) raise NotFound('List with key [{}] was not found.'.format(key)) # data = request.get_json() data = api.payload app.logger.info(data) list.deserialize(data) list.key = key list.save() return list.serialize(), status.HTTP_200_OK