def create_amenity(): """Example endpoint Creates an amenity Creates an amenity based on amenity_id with the JSON body --- definitions: Amenity: type: object properties: __class__: type: string description: The string of class object created_at: type: string description: The date the object created email: type: string first_name: type: string last_name: type: string id: type: string description: the id of the user updated_at: type: string description: The date the object was updated items: $ref: '#/definitions/Color' Color: type: string responses: 201: description: A list of dicts or dict, each dict is an amenity schema: $ref: '#/definitions/Amenity' examples: [{"__class__": "Amenity", "created_at": "2017-03-25T02:17:06", "id": "cf701d1a-3c19-4bac-bd99-15321f1140f2", "name": "Dog(s)", "updated_at": "2017-03-25T02:17:06"}] """ try: r = request.get_json() except: r = None if r is None: return "Not a JSON", 400 if 'name' not in r.keys(): return "Missing name", 400 s = Amenity(**r) s.save() return jsonify(s.to_json()), 201
def post_amenity(): """ Put an amenity """ body = request.get_json(silent=True) if not body: return make_response(jsonify({'error': 'Not a JSON'}), 400) if 'name' not in body: return make_response(jsonify({'error': 'Missing name'}), 400) new_amenity = Amenity(**body) storage.new(new_amenity) storage.save() return make_response(jsonify(new_amenity.to_dict()), 201)
def create_amenity(): """Creates a new amenity""" body = request.get_json(silent=True) if body is None: return jsonify({'error': 'Not a JSON'}), 400 if 'name' in body: new_amenity = Amenity(**body) storage.new(new_amenity) storage.save() return jsonify(new_amenity.to_dict()), 201 else: return jsonify({'error': 'Missing name'}), 400
def create_new_amenity(state_id=None): """ create new resource by my list of amenities """ amenity_object_json = request.get_json() if amenity_object_json is None: return jsonify({'Error': 'Not a JSON'}), 400 if 'name' not in amenity_object_json.keys(): return jsonify({'Error': 'Missing name'}), 400 amenity_object = Amenity(**amenity_object_json) amenity_object.save() return jsonify(amenity_object.to_dict()), 201
def create_new_amenity(state_id=None): """ create new resource by my list of amenities """ amenity_object_json = request.get_json() if amenity_object_json is None: abort(400, "Not a JSON") if 'name' not in amenity_object_json.keys(): abort(400, "Missing name") amenity_object = Amenity(**amenity_object_json) amenity_object.save() return jsonify(amenity_object.to_dict()), 201
def all_amenities(): if request.method == 'POST': posted_obj = request.get_json() if posted_obj is None: return ("Not a JSON", 400) if 'name' not in posted_obj: return ("Missing name", 400) new_obj = Amenity(**posted_obj) new_obj.save() return (jsonify(new_obj.to_json()), 201) rtn_json = [] all_obj = storage.all('Amenity') for instance in all_obj: rtn_json.append(all_obj[instance].to_json()) return (jsonify(rtn_json))
def create_amenity(): '''This is the 'create_amenity' method. Creates a new Amenity object. ''' try: r = request.get_json() except: r = None if r is None: return "Not a JSON", 400 if 'name' not in r.keys(): return "Missing name", 400 amenity = Amenity(**r) amenity.save() return jsonify(amenity.to_json()), 201