diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-23 18:04:03 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-23 18:04:03 -0700 |
commit | fbeb6f39552bb1602beb9420be551a7ad34d9afb (patch) | |
tree | 93a2b3be6c6db3234ff39d8067cb9461bcee35fd | |
parent | 5416a2570e7167ca2e62352dda10d2f371b994a7 (diff) | |
download | fatcat-fbeb6f39552bb1602beb9420be551a7ad34d9afb.tar.gz fatcat-fbeb6f39552bb1602beb9420be551a7ad34d9afb.zip |
some basic routing
-rw-r--r-- | fatcat/api.py | 12 | ||||
-rw-r--r-- | 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/<int:ident>', 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/<int:ident>', 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/<int:ident>', methods=['GET']) def creator_view(ident): rv = api.api_creator_get(ident) |