diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-09-19 08:32:13 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-09-19 08:32:13 -0400 |
commit | f00557d6b90f6ebdb99b21dd281068701961b30c (patch) | |
tree | c5d003544a18a397c47b6c32e6d9721886cd81ea /gitsrht/blueprints/api.py | |
parent | d01d4b9264576e5409899558152089c4dc1cbf2b (diff) |
Break ground on the API
Diffstat (limited to 'gitsrht/blueprints/api.py')
-rw-r--r-- | gitsrht/blueprints/api.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gitsrht/blueprints/api.py b/gitsrht/blueprints/api.py new file mode 100644 index 0000000..82318a9 --- /dev/null +++ b/gitsrht/blueprints/api.py @@ -0,0 +1,33 @@ +from flask import Blueprint, request +from gitsrht.types import Repository, RepoVisibility +from gitsrht.access import UserAccess, has_access, get_repo +from srht.oauth import oauth + +api = Blueprint("api", __name__) + +repo_json = lambda r: { + "id": r.id, + "name": r.name, + "description": r.description, + "created": r.created, + "updated": r.updated, + "visibility": r.visibility.value +} + +@api.route("/api/repos") +@oauth("repos") +def repos_GET(oauth_token): + start = request.args.get('start') or -1 + repos = Repository.query.filter(Repository.owner_id == oauth_token.user_id) + if start != -1: + repos = repos.filter(Repository.id <= start) + repos = repos.order_by(Repository.id.desc()).limit(11).all() + if len(repos) != 11: + next_id = -1 + else: + next_id = repos[-1].id + repos = repos[:10] + return { + "next": next_id, + "results": [repo_json(r) for r in repos] + } |