-
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
93f999b
commit 9df0660
Showing
13 changed files
with
382 additions
and
107 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,70 @@ | ||
from ..api import rule | ||
from ..api._endpoint import ApiEndpoint | ||
from ..entities._entity import NotFound | ||
from ..entities.distribution import Distribution, DistributionSerializer | ||
|
||
|
||
class DistributionListAPI(ApiEndpoint): | ||
serializer = DistributionSerializer() | ||
|
||
def _get(self): | ||
return Distribution.all() | ||
|
||
def get(self): | ||
""" | ||
--- | ||
description: Get a list of distributions. | ||
responses: | ||
"200": "DistributionList" | ||
"401": "401" | ||
"404": "404" | ||
tags: | ||
- Distributions | ||
""" | ||
distributions = Distribution.all() | ||
return self.serializer.many.dump(distributions) | ||
|
||
|
||
class DistributionEntityAPI(ApiEndpoint): | ||
serializer = DistributionSerializer() | ||
|
||
def _get(self, distribution_id): | ||
try: | ||
distribution = Distribution.one(id=distribution_id) | ||
except NotFound: | ||
self.abort_404_not_found() | ||
return distribution | ||
|
||
def get(self, distribution_id): | ||
""" | ||
--- | ||
description: Get a distribution. | ||
responses: | ||
"200": "DistributionEntity" | ||
"401": "401" | ||
"404": "404" | ||
parameters: | ||
- name: distribution_id | ||
in: path | ||
schema: | ||
type: string | ||
tags: | ||
- Distributions | ||
""" | ||
distribution = self._get(distribution_id) | ||
return self.serializer.one.dump(distribution) | ||
|
||
|
||
distribution_entity_view = DistributionEntityAPI.as_view("distribution") | ||
distribution_list_view = DistributionListAPI.as_view("distributions") | ||
|
||
rule( | ||
"/distributions/<distribution_id>/", | ||
view_func=distribution_entity_view, | ||
methods=["GET"], | ||
) | ||
rule( | ||
"/distributions/", | ||
view_func=distribution_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
Oops, something went wrong.