def get_rotation(pk): try: rotation = RotationUrl.query.get(pk) except IntegrityError: return jsonify({"message": "Rotation could not be found."}), 404 rotation_result = rotation_schema.dump(rotation) return jsonify(rotation_result.data)
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})