Skip to content

Commit

Permalink
refactor: add ProjectProjection
Browse files Browse the repository at this point in the history
  • Loading branch information
psincraian committed Nov 4, 2018
1 parent c37bffc commit d2e1c48
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 17 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ yoyo-migrations = "*"
Flask = "*"
Flask-WTF = "*"
passlib = "*"
orator = "*"

[dev-packages]
behave = "*"
Expand Down
178 changes: 177 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions pepy/application/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

from pepy.domain.exception import ProjectNotFoundException
from pepy.domain.model import ProjectName, Badge, Project, ProjectDownloads, Downloads
from pepy.domain.read_model import ProjectProjection
from pepy.domain.repository import ProjectRepository
from pepy.domain.view import ProjectView


class DownloadsNumberFormatter:
Expand Down Expand Up @@ -33,11 +35,12 @@ def generate_badge(self, project_name: ProjectName) -> Badge:


class ProjectProvider:
def __init__(self, project_repository: ProjectRepository):
def __init__(self, project_repository: ProjectRepository, project_view: ProjectView):
self._project_repository = project_repository
self._project_view = project_view

def find(self, project_name: ProjectName) -> Project:
project = self._project_repository.find(project_name)
def find(self, project_name: str) -> ProjectProjection:
project = self._project_view.find(project_name)
if project is None:
raise ProjectNotFoundException(project_name)
return project
Expand Down
4 changes: 2 additions & 2 deletions pepy/domain/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def message(self) -> str:


class ProjectNotFoundException(DomainException):
def __init__(self, project_name: ProjectName):
def __init__(self, project_name: str):
self.project_name = project_name

def message(self) -> str:
return "Project with name {} does not exist".format(self.project_name.name)
return "Project with name {} does not exist".format(self.project_name)


class ProjectNameLengthIsNotValidException(DomainException):
Expand Down
23 changes: 23 additions & 0 deletions pepy/domain/read_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import date
from typing import List

from attr import attrs, attrib


@attrs()
class ProjectListProjection:
name: str = attrib()
total_downloads: int = attrib()


@attrs()
class DownloadProjection:
date: date = attrib()
downloads: int = attrib()


@attrs()
class ProjectProjection:
name: str = attrib()
total_downloads: int = attrib()
last_downloads: List[DownloadProjection] = attrib() # the last 30 days downloads
10 changes: 10 additions & 0 deletions pepy/domain/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from abc import ABC, abstractmethod
from typing import Optional

from pepy.domain.read_model import ProjectProjection


class ProjectView(ABC):
@abstractmethod
def find(self, project_name: str) -> Optional[ProjectProjection]:
pass
3 changes: 3 additions & 0 deletions pepy/infrastructure/container/_config/_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
SECRET_KEY = "1234"

DATABASE = {"host": "pgsql", "user": "pepy", "password": "pepy", "database": "pepy"}
DATABASE_ORATOR = {
"prope": {"driver": "postgres", "host": "pgsql", "user": "pepy", "password": "pepy", "database": "pepy"}
}

# password: pepyrocks
ADMIN_PASSWORD = "$pbkdf2-sha256$29000$uXcOobS2FiIkJCSkFGJszQ$TwCkC7lAIvOTrPjWmVr3LGDVAAK68CjWW7niKoI6dzo"
Expand Down
10 changes: 10 additions & 0 deletions pepy/infrastructure/container/_config/_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
"database": os.environ.get("PEPY_DATABASE_NAME"),
}

DATABASE_ORATOR = {
"prope": {
"driver": "postgres",
"host": os.environ.get("PEPY_DATABASE_HOST"),
"user": os.environ.get("PEPY_DATABASE_USER"),
"password": os.environ.get("PEPY_DATABASE_PASSWORD"),
"database": os.environ.get("PEPY_DATABASE_NAME"),
}
}

ADMIN_PASSWORD = os.environ.get("PEPY_ADMIN_PASSWORD")
BQ_CREDENTIALS_FILE = os.environ.get("PEPY_BIGQUERY_CREDENTIALS")
LOGGING_FILE = os.environ.get("PEPY_LOGGING_FILE")
3 changes: 3 additions & 0 deletions pepy/infrastructure/container/_config/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
DEBUG = True

DATABASE = {"host": "pgsql", "user": "pepy", "password": "pepy", "database": "pepy_test"}
DATABASE_ORATOR = {
"prope": {"driver": "postgres", "host": "pgsql", "user": "pepy", "password": "pepy", "database": "pepy_test"}
}

# password: pepyrocks
ADMIN_PASSWORD = "$pbkdf2-sha256$29000$uXcOobS2FiIkJCSkFGJszQ$TwCkC7lAIvOTrPjWmVr3LGDVAAK68CjWW7niKoI6dzo"
Expand Down
Loading

0 comments on commit d2e1c48

Please sign in to comment.