-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
23 changed files
with
301 additions
and
284 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 |
---|---|---|
|
@@ -4,5 +4,5 @@ app: | |
from_address: "[email protected]" | ||
admin_name: "John Doe" | ||
admin_address: "[email protected]" | ||
dsn: !ENV ${MAILER_DSN} | ||
db_connection_url: !ENV ${DB_CONNECTION_URL} | ||
dsn: "smtp://invalid" | ||
db_connection_url: "sqlite:///var/blog.db" |
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
File renamed without changes.
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,9 @@ | ||
from wireup import container, initialize_container | ||
|
||
from demoapp import services | ||
from demoapp.commands import cli | ||
from demoapp.config import get_config | ||
|
||
if __name__ == "__main__": | ||
initialize_container(container, parameters=get_config(), service_modules=[services]) | ||
cli() |
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,13 @@ | ||
import click | ||
|
||
from demoapp.commands.create_database_command import create_db | ||
from demoapp.commands.create_post_command import create_post | ||
|
||
|
||
@click.group() | ||
def cli() -> None: | ||
pass | ||
|
||
|
||
cli.add_command(create_post) | ||
cli.add_command(create_db) |
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,19 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import click | ||
from wireup import container | ||
|
||
from demoapp.models.db import DbBaseModel | ||
from demoapp.services.database_connection import DatabaseConnection | ||
|
||
|
||
@click.command() | ||
@container.autowire | ||
def create_db(db: DatabaseConnection) -> None: | ||
path = Path(sys.argv[0]).parent.parent / "var" | ||
|
||
if not path.exists(): | ||
Path.mkdir(path) | ||
|
||
DbBaseModel.metadata.create_all(db.engine) |
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,19 @@ | ||
from datetime import datetime, timezone | ||
|
||
import click | ||
from wireup import container | ||
|
||
from demoapp.models.api import PostCreateModel | ||
from demoapp.services.post_service import PostService | ||
|
||
|
||
@click.command() | ||
@click.argument("title") | ||
@click.argument("contents") | ||
@container.autowire | ||
def create_post(title: str, contents: str, post_service: PostService) -> None: | ||
post = post_service.create_post( | ||
PostCreateModel(title=title, content=contents, created_at=datetime.now(tz=timezone.utc)) | ||
) | ||
|
||
click.echo(f"Created post with id: {post.id}") |
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 @@ | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
|
||
def get_config() -> dict[str, Any]: | ||
# Load all configuration from yaml into a dict then register them in the container. | ||
# Services asking for parameter can reference them by name. | ||
# Note that types don't have to be just scalar values. | ||
# notification_mailer is a dataclass that will get injected as a parameter. | ||
app_dir = Path(__file__).parent.parent | ||
|
||
with Path.open(Path(f"{app_dir}/config/parameters.yaml")) as f: | ||
all_config = yaml.unsafe_load(f) | ||
|
||
return all_config["app"] |
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 |
---|---|---|
@@ -1,28 +1,33 @@ | ||
from datetime import datetime, timezone | ||
|
||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy import DateTime, ForeignKey, Integer, String | ||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship | ||
|
||
DbBaseModel = declarative_base() | ||
|
||
class DbBaseModel(DeclarativeBase): | ||
pass | ||
|
||
|
||
class Post(DbBaseModel): | ||
__tablename__ = "posts" | ||
|
||
id: Column[int] = Column(Integer, primary_key=True) | ||
title: Column[str] = Column(String(255), nullable=False) | ||
content: Column[str] = Column(String, nullable=False) | ||
created_at: Column[datetime] = Column(DateTime, default=lambda: datetime.now(tz=timezone.utc)) | ||
id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
title: Mapped[str] = mapped_column(String(255), nullable=False) | ||
content: Mapped[str] = mapped_column(String, nullable=False) | ||
created_at: Mapped[datetime] = mapped_column( | ||
DateTime, default=lambda: datetime.now(tz=timezone.utc) | ||
) | ||
|
||
comments = relationship("Comment", backref="post", lazy=True) | ||
|
||
|
||
class Comment(DbBaseModel): | ||
__tablename__ = "comments" | ||
|
||
id: Column[int] = Column(Integer, primary_key=True) | ||
content: Column[str] = Column(String, nullable=False) | ||
created_at: Column[datetime] = Column(DateTime, default=lambda: datetime.now(tz=timezone.utc)) | ||
id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
content: Mapped[str] = mapped_column(String, nullable=False) | ||
created_at: Mapped[datetime] = mapped_column( | ||
DateTime, default=lambda: datetime.now(tz=timezone.utc) | ||
) | ||
|
||
post_id: Column[int] = Column(Integer, ForeignKey("posts.id"), nullable=False) | ||
post_id: Mapped[int] = mapped_column(Integer, ForeignKey("posts.id"), nullable=False) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.