예제 #1
0
def create_amenity():
    try:
        new_amenity = Amenity(name=request.form['name'])
        new_amenity.save()
        return jsonify(new_amenity.to_dict())
    except:
        return jsonify({'code': 10003, 'msg': 'Name already exists'}), 409
예제 #2
0
def create_amenity():
    try:
        new_amenity = Amenity(name=request.form['name'])
        new_amenity.save()
        return jsonify(new_amenity.to_dict())
    except:
        return jsonify({'code': 10003, 'msg': 'Name already exists'}), 409
예제 #3
0
def amenities():
	if request.method == 'GET':
		amenities = Amenity.select()
		return ListStyle.list(amenities, request), 200

	elif request.method == 'POST':
		try:
			if "name" not in request.form:
				return json_response(status_=400, msg="missing parameters", code=40000)
				
			test = Amenity.select().where(Amenity.name == request.form["name"])

			if test.wrapped_count() > 0:
				return json_response(status_=409, code=10002, msg="place already exists with this name")

			amenity = Amenity(name=request.form["name"])
			amenity.save()
			return jsonify(amenity.to_dict()), 201

		except IntegrityError:
			return json_response(status_=409,
								msg="Name already exists",
								code=10003)