Esempio n. 1
0
def new_rotation():
    json_data = request.get_json()
    if not json_data:
        return jsonify({"message": "No input data provided"}), 400
        # Validate and deserialize input
    data, errors = rotation_schema.load(json_data)
    if errors:
        return jsonify(errors), 422
    url, seconds, reload = data["url"], data.get("seconds", None), data.get("reload", None)
    rotation = RotationUrl.query.filter_by(url=url).first()
    if rotation is None:
        # Create a new rotation
        rotation = RotationUrl(url=url, seconds=seconds, reload=reload)
        db_session.add(rotation)

    db_session.commit()
    result = rotation_schema.dump(RotationUrl.query.get(rotation.id))
    return jsonify({"message": "Created new rotation url.", "rotation": result.data})
Esempio n. 2
0
def add_allrotations():
    json_data = request.get_json()
    if not json_data:
        return jsonify({"message": "No input data provided"}), 400

    RotationUrl.query.delete()

    for u in json_data:
        # Validate and deserialize input
        data, errors = rotation_schema.load(u)
        if errors:
            return jsonify(errors), 422
        url, seconds, reload = data["url"], data.get("seconds", None), data.get("reload", None)
        # Create a new rotation
        rotation = RotationUrl(url=url, seconds=seconds, reload=reload)
        db_session.add(rotation)

    db_session.commit()
    return jsonify({"message": "Rotations were all added successfully"})