-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
432d132
commit b3cf4ee
Showing
7 changed files
with
89 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json | ||
|
||
from flask import Blueprint | ||
from pepy.infrastructure import container | ||
from pepy.infrastructure.api._transformer import transform_project, transform_project_item | ||
|
||
api = Blueprint('api', __name__) | ||
|
||
@api.route("/projects/<project_name>", methods=["GET"]) | ||
def project_action(project_name): | ||
project = container.project_provider.find(project_name) | ||
return json.dumps(transform_project(project)) | ||
|
||
|
||
@api.route("/projects", methods=["GET"]) | ||
def project_find(): | ||
projects = container.project_provider.for_home() | ||
return json.dumps([transform_project_item(p) for p in projects]) |
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,18 @@ | ||
from typing import Dict | ||
|
||
from pepy.domain.read_model import ProjectProjection, ProjectListProjection | ||
|
||
|
||
def transform_project(project: ProjectProjection) -> Dict: | ||
return { | ||
"id": project.name, | ||
"total_downloads": project.total_downloads, | ||
"downloads": {d.date.isoformat(): d.downloads for d in project.last_downloads} | ||
} | ||
|
||
|
||
def transform_project_item(project: ProjectListProjection) -> Dict: | ||
return { | ||
"id": project.name, | ||
"total_downloads": project.total_downloads, | ||
} |
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,17 @@ | ||
Feature: show index page with some selected projects | ||
|
||
Scenario: show the projects with most downloads from yesterday | ||
Given the following projects exists | ||
| name | downloads | | ||
| pepy | 100 | | ||
When I send the GET request to /api/projects | ||
Then the response status code should be 200 | ||
And the api response should be | ||
""" | ||
[ | ||
{ | ||
"id": "pepy", | ||
"total_downloads": 100 | ||
} | ||
] | ||
""" |
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,22 @@ | ||
Feature: show index page with some selected projects | ||
|
||
Scenario: show the projects with most downloads from yesterday | ||
Given the pepy project with the following downloads | ||
| date | downloads | | ||
| 2018-05-01 | 10 | | ||
| 2018-05-02 | 15 | | ||
| 2018-05-03 | 20 | | ||
When I send the GET request to /api/projects/pepy | ||
Then the response status code should be 200 | ||
And the api response should be | ||
""" | ||
{ | ||
"id": "pepy", | ||
"total_downloads": 45, | ||
"downloads": { | ||
"2018-05-03": 20, | ||
"2018-05-02": 15, | ||
"2018-05-01": 10 | ||
} | ||
} | ||
""" |
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