Example #1
0
def update_request(id):
    user = g.user
    req = session.query(Request).filter(
        and_(Request.id == id, user.id != Request.user_id))
    if not req:
        abort(400)

    errors = Request.validate(request.json)
    if len(errors) == 0:
        meal_type = request.json.get('meal_type')
        location_string = request.json.get('location_string')
        latitude = request.json.get('latitude')
        longitude = request.json.get('longitude')
        meal_time = request.json.get('meal_time')
        new_req = {
            'meal_type': meal_type,
            'meal_time': meal_time,
            'latitude': latitude,
            'longitude': longitude,
            'location_string': location_string
        }
        req.update(new_req)
        session.commit()
        return jsonify({'response': True})
    else:
        return jsonify({'errors': errors}), 400
def update_request(id):
    user = g.user
    if not request.json:
        abort(400)
    errors = Request.validate(request.json)
    if len(errors) == 0:
        return  jsonify( { 'result': True } )

    return jsonify({"message": "The request is invalid."},errors = [error for error in errors])  ,400
Example #3
0
def update_request(id):
    user = g.user
    if not request.json:
        abort(400)
    errors = Request.validate(request.json)
    if len(errors) == 0:
        return jsonify({'result': True})

    return jsonify({"message": "The request is invalid."},
                   errors=[error for error in errors]), 400
def new_request():
    user = g.user
    if not request.json:
        abort(400)
    errors = Request.validate(request.json)
    if len(errors) == 0:
        meal_type = request.json.get('meal_type')
        longitude = request.json.get('longitude')
        latitude = request.json.get('latitude')
        location_string = request.json.get('location_string')
        meal_time = request.json.get('meal_time')
        r = Request(user_id = user.id,meal_type = meal_type, longitude = longitude, latitude = latitude, location_string = location_string, meal_time = meal_time)
        session.add(r)
        session.commit()
        return  jsonify( { 'result': True } ),201
    return jsonify({"message": "The request is invalid."},errors = [error for error in errors])  ,400
Example #5
0
def create_newrequest():
    errors = Request.validate(request.json)
    if len(errors) == 0:
        user = g.user
        meal_type = request.json.get('meal_type')
        location_string = request.json.get('location_string')
        latitude = request.json.get('latitude')
        longitude = request.json.get('longitude')
        meal_time = request.json.get('meal_time')

        req = Request(meal_type = meal_type, meal_time = meal_time, \
                      location_string = location_string, user_id = user.id, \
                      latitude = latitude, longitude = longitude)
        session.add(req)
        session.commit()
        return jsonify({'result': True}), 201
    else:
        return jsonify({'errors': errors}), 400
Example #6
0
def new_request():
    user = g.user
    if not request.json:
        abort(400)
    errors = Request.validate(request.json)
    if len(errors) == 0:
        meal_type = request.json.get('meal_type')
        longitude = request.json.get('longitude')
        latitude = request.json.get('latitude')
        location_string = request.json.get('location_string')
        meal_time = request.json.get('meal_time')
        r = Request(user_id=user.id,
                    meal_type=meal_type,
                    longitude=longitude,
                    latitude=latitude,
                    location_string=location_string,
                    meal_time=meal_time)
        session.add(r)
        session.commit()
        return jsonify({'result': True}), 201
    return jsonify({"message": "The request is invalid."},
                   errors=[error for error in errors]), 400