From fbeb6f39552bb1602beb9420be551a7ad34d9afb Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 23 Apr 2018 18:04:03 -0700 Subject: some basic routing --- fatcat/api.py | 12 ++++++------ fatcat/routes.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fatcat/api.py b/fatcat/api.py index 9f2ed29a..838168af 100644 --- a/fatcat/api.py +++ b/fatcat/api.py @@ -33,12 +33,7 @@ def api_work_get(ident): @app.route('/v0/work', methods=['POST']) def api_work_create(): - """ - 1. find or create edit_group - 2. create work_edit, work_rev, work_ident - - TODO: use marshmallow? - """ + # TODO: Special-case to pull out primary and create that? params = request.get_json() edit_group = get_or_create_edit_group(params.get('editgroup')) rev = WorkRev( @@ -101,6 +96,11 @@ def api_release_create(): db.session.commit() return release_schema.jsonify(ident) +@app.route('/v0/release/random', methods=['GET']) +def api_release_random(): + entity = ReleaseIdent.query.order_by(db.func.random()).first() + return redirect('/v0/release/{}'.format(entity.id)) + @app.route('/v0/creator/', methods=['GET']) def api_creator_get(ident): diff --git a/fatcat/routes.py b/fatcat/routes.py index c4cde22a..2e77e7ac 100644 --- a/fatcat/routes.py +++ b/fatcat/routes.py @@ -14,8 +14,9 @@ def work_create(): @app.route('/work/random', methods=['GET']) def work_random(): - rv = app.get('/v0/work/random') - return redirect(rv.location) + rv = api.api_work_random() + ident = rv.location.split('/')[-1] + return redirect("/work/{}".format(ident)) @app.route('/work/', methods=['GET']) def work_view(ident): @@ -35,6 +36,12 @@ def release_view(ident): entity = json.loads(rv.data.decode('utf-8')) return render_template('release_view.html', release=entity) +@app.route('/release/random', methods=['GET']) +def release_random(): + rv = api.api_release_random() + ident = rv.location.split('/')[-1] + return redirect("/release/{}".format(ident)) + @app.route('/creator/', methods=['GET']) def creator_view(ident): rv = api.api_creator_get(ident) -- cgit v1.2.3