-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57928cf
commit 16ac362
Showing
10 changed files
with
221 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from ..api import rule | ||
from ..api._endpoint import ApiEndpoint | ||
from ..entities._entity import NotFound | ||
from ..entities.commit import Commit, CommitSerializer | ||
|
||
|
||
class CommitListAPI(ApiEndpoint): | ||
serializer = CommitSerializer() | ||
|
||
def get(self): | ||
""" | ||
--- | ||
description: Get a list of commits. | ||
responses: | ||
"200": "CommitList" | ||
"401": "401" | ||
tags: | ||
- Commits | ||
""" | ||
commits = Commit.all(order_by=Commit.timestamp.desc(), limit=500) | ||
return self.serializer.many.dump(commits) | ||
|
||
|
||
class CommitEntityAPI(ApiEndpoint): | ||
serializer = CommitSerializer() | ||
|
||
def _get(self, commit_id): | ||
try: | ||
commit = Commit.one(id=commit_id) | ||
except NotFound: | ||
self.abort_404_not_found() | ||
return commit | ||
|
||
def get(self, commit_id): | ||
""" | ||
--- | ||
description: Get a commit. | ||
responses: | ||
"200": "CommitEntity" | ||
"401": "401" | ||
"404": "404" | ||
parameters: | ||
- name: commit_id | ||
in: path | ||
schema: | ||
type: string | ||
tags: | ||
- Commits | ||
""" | ||
commit = self._get(commit_id) | ||
return self.serializer.one.dump(commit) | ||
|
||
|
||
commit_entity_view = CommitEntityAPI.as_view("commit") | ||
commit_list_view = CommitListAPI.as_view("commits") | ||
|
||
rule( | ||
"/commits/<commit_id>/", | ||
view_func=commit_entity_view, | ||
methods=["GET"], | ||
) | ||
rule( | ||
"/commits/", | ||
view_func=commit_list_view, | ||
methods=["GET"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.