Skip to content

Commit

Permalink
Reorganize app
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Aug 24, 2024
1 parent 08c9731 commit d806b50
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion config/parameters.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app:
notification_mailer: !!python/object:demoapp.model.config.NotificationMailerConfig
notification_mailer: !!python/object:demoapp.models.config.NotificationMailerConfig
from_name: "Example Blog Postmaster"
from_address: "[email protected]"
admin_name: "John Doe"
Expand Down
5 changes: 3 additions & 2 deletions demoapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from pyaml_env import parse_config
from wireup import container, initialize_container

from demoapp.blueprint.post import bp as post_blueprint
from demoapp import services
from demoapp.blueprints.post import bp as post_blueprint


def create_app() -> Flask:
Expand All @@ -17,7 +18,7 @@ def create_app() -> Flask:
# notification_mailer is a dataclass that will get injected as a parameter.
all_config = parse_config("config/parameters.yaml", loader=yaml.Loader)
container.params.update(all_config["app"])
initialize_container(container, service_modules=[])
initialize_container(container, service_modules=[services])

return flask_app

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions demoapp/blueprint/post.py → demoapp/blueprints/post.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Annotated

import flask
from flask import Blueprint, Response, abort
from flask import Blueprint, Response, abort, jsonify
from wireup import Inject, container

from demoapp.model.api import PostCreateModel
from demoapp.service.post_repository import PostRepository
from demoapp.service.post_service import PostService
from demoapp.models.api import PostCreateModel
from demoapp.services.post_repository import PostRepository
from demoapp.services.post_service import PostService
from demoapp.util import ApiEndpoint, ApiResponse

bp = Blueprint("post", __name__, url_prefix="/posts")
Expand All @@ -18,7 +18,7 @@
# to the method than the flask one so that it is executed before it.
@container.autowire
def get_posts(post_repository: PostRepository) -> Response:
return ApiResponse.ok(post_repository.find_all())
return jsonify(post_repository.find_all())


@bp.post("/")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from wireup import Inject, abstract, service

from demoapp.model.app import EmailAddress, EmailMessage
from demoapp.model.config import NotificationMailerConfig
from demoapp.model.db import Post
from demoapp.models.app import EmailAddress, EmailMessage
from demoapp.models.config import NotificationMailerConfig
from demoapp.models.db import Post


# Declare an abstract type as an "interface".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from wireup import service

from demoapp.model.api import PostGetModel
from demoapp.model.db import Post
from demoapp.service.database_connection import DatabaseConnection
from demoapp.models.api import PostGetModel
from demoapp.models.db import Post
from demoapp.services.database_connection import DatabaseConnection


@service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from wireup import service

from demoapp.model.api import PostCreateModel
from demoapp.model.db import Post
from demoapp.service.mailer_service import MailerService
from demoapp.service.post_repository import PostRepository
from demoapp.models.api import PostCreateModel
from demoapp.models.db import Post
from demoapp.services.mailer_service import MailerService
from demoapp.services.post_repository import PostRepository


# Register a Post service. Registration can be done on dataclasses as well,
Expand Down
2 changes: 1 addition & 1 deletion demoapp/util/api_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel
from sqlalchemy import inspect

from demoapp.model.db import DbBaseModel
from demoapp.models.db import DbBaseModel

Model = BaseModel | DbBaseModel
ResponseObject = list[Model] | Model
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions test/fixtures.py → tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import datetime

from demoapp.model.api import PostGetModel
from demoapp.model.db import Post
from demoapp.service.mailer_service import MailerService
from demoapp.models.api import PostGetModel
from demoapp.models.db import Post
from demoapp.services.mailer_service import MailerService


def make_db_post(i: int) -> Post:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase

from demoapp.service.database_connection import DatabaseConnection
from demoapp.services.database_connection import DatabaseConnection


class DatabaseConnectionTest(TestCase):
Expand Down
8 changes: 4 additions & 4 deletions test/test_mailer.py → tests/test_mailer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from test.fixtures import make_db_post
from unittest import TestCase

from demoapp.model.app import EmailAddress, EmailMessage
from demoapp.model.config import NotificationMailerConfig
from demoapp.service.mailer_service import MailerServiceImpl
from demoapp.models.app import EmailAddress, EmailMessage
from demoapp.models.config import NotificationMailerConfig
from demoapp.services.mailer_service import MailerServiceImpl
from tests.fixtures import make_db_post


class TestMailerImpl(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
from test.fixtures import make_api_post, make_db_post
from unittest import TestCase

from demoapp.model.db import DbBaseModel, Post
from demoapp.service.database_connection import DatabaseConnection
from demoapp.service.post_repository import PostRepository
from demoapp.models.db import DbBaseModel, Post
from demoapp.services.database_connection import DatabaseConnection
from demoapp.services.post_repository import PostRepository
from tests.fixtures import make_api_post, make_db_post


class DatabaseConnectionTest(TestCase):
Expand Down
12 changes: 6 additions & 6 deletions test/test_post_service.py → tests/test_post_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest
from datetime import datetime
from test.fixtures import TestMailer

from demoapp.model.api import PostCreateModel
from demoapp.model.db import DbBaseModel
from demoapp.service.database_connection import DatabaseConnection
from demoapp.service.post_repository import PostRepository
from demoapp.service.post_service import PostService
from demoapp.models.api import PostCreateModel
from demoapp.models.db import DbBaseModel
from demoapp.services.database_connection import DatabaseConnection
from demoapp.services.post_repository import PostRepository
from demoapp.services.post_service import PostService
from tests.fixtures import TestMailer


class TestPostService(unittest.TestCase):
Expand Down

0 comments on commit d806b50

Please sign in to comment.