Пример #1
0
def generate_random():
    start_id = flask.request.args.get("startId", type=int)
    count = flask.request.args.get("count", type=int)
    with flask.current_app.ydb.session as session:
        series_repository = SeriesRepository(session)
        for series_id in xrange(start_id, start_id + count):
            series_repository.insert(Series(
                series_id=series_id,
                title="Name " + str(series_id),
                series_info="Info " + str(series_id),
                release_date=datetime.datetime.now().date(),
                views=random.randint(0, 1000000)
            ))
    return "OK"
Пример #2
0
def list_series():
    with flask.current_app.ydb.session as session:
        series = SeriesRepository(session).find_all(
            limit=flask.request.args.get("limit", default=10, type=int),
            last_series_id=flask.request.args.get("lastSeriesId", type=int),
        )
    return flask.jsonify(series=[item.export() for item in series])
Пример #3
0
def insert():
    try:
        series = Series.from_dict(flask.request.get_json())
    except (ValueError, KeyError):
        return "ERROR Invalid Series object"
    with flask.current_app.ydb.session as session:
        SeriesRepository(session).insert(series)
    return "OK"
Пример #4
0
def update_views(series_id, new_views):
    with flask.current_app.ydb.session as session:
        return str(SeriesRepository(session).update_views(series_id, new_views))
Пример #5
0
def delete(series_id):
    with flask.current_app.ydb.session as session:
        return str(SeriesRepository(session).delete(series_id))
Пример #6
0
def drop_tables():
    with flask.current_app.ydb.session as session:
        SeriesRepository(session).drop_tables()
    return "OK"