Skip to content

Commit

Permalink
pre-commit에 black 룰 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
riroan committed Aug 24, 2024
1 parent 9f9ed82 commit 2655be2
Show file tree
Hide file tree
Showing 30 changed files with 278 additions and 376 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12]

steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ repos:
rev: 5.13.2
hooks:
- id: isort
args: ["--profile=black", "--py=312", "--line-length=80"]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==24.4.21
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
language_version: python3.12
args: ["--line-length=80"]
5 changes: 3 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

Expand All @@ -15,7 +14,9 @@ def create_app(settings: Settings):

app.add_middleware(
CORSMiddleware,
allow_origins=["*",],
allow_origins=[
"*",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
10 changes: 3 additions & 7 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

class Database:
def __init__(self, settings: Settings):
self.engine = create_engine(
url=settings.get_db_url()
)
self.engine = create_engine(url=settings.get_db_url())
self.session = sessionmaker(
autocommit=False,
autoflush=False,
bind=self.engine
autocommit=False, autoflush=False, bind=self.engine
)

def get_session(self) -> Session:
return self.session()

def __new__(cls, settings: Settings):
if not hasattr(cls, 'instance'):
if not hasattr(cls, "instance"):
cls.instance = super(Database, cls).__new__(cls)
return cls.instance
8 changes: 2 additions & 6 deletions depends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ async def get_database(
return Database(settings)


async def get_session(
database: Annotated[Database, Depends(get_database)]
):
async def get_session(database: Annotated[Database, Depends(get_database)]):
session = database.get_session()
try:
yield session
Expand All @@ -30,7 +28,5 @@ async def get_session(
raise e


async def get_messagebus(
session: Annotated[Session, Depends(get_session)]
):
async def get_messagebus(session: Annotated[Session, Depends(get_session)]):
return MessageBus(session)
14 changes: 3 additions & 11 deletions depends/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@


async def add_cart_command(cart: CartDto):
return AddCartCommand(
user_id=cart.user_id,
product_id=cart.product_id
)
return AddCartCommand(user_id=cart.user_id, product_id=cart.product_id)


async def update_cart_command(cart: CartUpdateDto, cart_id: int):
return UpdateCartCommand(
cart_id=cart_id,
count=cart.count
)
return UpdateCartCommand(cart_id=cart_id, count=cart.count)


async def delete_cart_command(cart_id: int):
return DeleteCartCommand(
cart_id=cart_id
)
return DeleteCartCommand(cart_id=cart_id)
6 changes: 2 additions & 4 deletions depends/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

async def like_command(like_data: LikeDto):
return LikeCommand(
user_id=like_data.user_id,
product_id=like_data.product_id
user_id=like_data.user_id, product_id=like_data.product_id
)


async def dislike_command(like_data: LikeDto):
return DislikeCommand(
user_id=like_data.user_id,
product_id=like_data.product_id
user_id=like_data.user_id, product_id=like_data.product_id
)
2 changes: 1 addition & 1 deletion depends/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ async def add_product_command(product: ProductDto):
name=product.name,
image_path=product.image_path,
price=product.price,
summary=product.summary
summary=product.summary,
)
2 changes: 1 addition & 1 deletion dto/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def from_entity(like: Like):
return LikeResponseDto(
is_like=like.is_like,
user_id=like.user_id,
product_id=like.product_id
product_id=like.product_id,
)
5 changes: 2 additions & 3 deletions exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class NotFoundException(BaseException):

exception_mapper = {
BadRequestException: status.HTTP_400_BAD_REQUEST,
NotFoundException: status.HTTP_404_NOT_FOUND
NotFoundException: status.HTTP_404_NOT_FOUND,
}


def handle_exception(request: Request, exc: HTTPException):
for exception in exception_mapper:
if isinstance(exc, exception):
return JSONResponse(
status_code=exception_mapper[exception],
content=exc.message
status_code=exception_mapper[exception], content=exc.message
)
raise NotImplementedError
3 changes: 1 addition & 2 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
db_password = os.environ["DB_PASSWORD"]
db_port = os.environ["DB_PORT"]
url = (
f"mysql+pymysql://{db_user}:{db_password}"
f"@{db_host}:{db_port}/{db_name}"
f"mysql+pymysql://{db_user}:{db_password}" f"@{db_host}:{db_port}/{db_name}"
)
config.set_main_option("sqlalchemy.url", url)

Expand Down
192 changes: 125 additions & 67 deletions migrations/versions/46c6ea277f8a_001_initial_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,141 @@
from alembic import op

# revision identifiers, used by Alembic.
revision: str = '46c6ea277f8a'
revision: str = "46c6ea277f8a"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('product',
sa.Column('name', sa.String(length=256), nullable=False),
sa.Column('image_path', sa.String(
length=512), nullable=False),
sa.Column('price', sa.Integer(), nullable=False),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('email', sa.String(length=256), nullable=False),
sa.Column('password', sa.String(
length=256), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('like_history',
sa.Column('is_like', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('review',
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('comment', sa.Text(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('shopping_cart',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('count', sa.Integer(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(),
server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table(
"product",
sa.Column("name", sa.String(length=256), nullable=False),
sa.Column("image_path", sa.String(length=512), nullable=False),
sa.Column("price", sa.Integer(), nullable=False),
sa.Column("summary", sa.Text(), nullable=True),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"user",
sa.Column("email", sa.String(length=256), nullable=False),
sa.Column("password", sa.String(length=256), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"like_history",
sa.Column("is_like", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("product_id", sa.Integer(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["product_id"],
["product.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["user.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"review",
sa.Column("product_id", sa.Integer(), nullable=False),
sa.Column("comment", sa.Text(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["product_id"],
["product.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"shopping_cart",
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("product_id", sa.Integer(), nullable=False),
sa.Column("count", sa.Integer(), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["product_id"],
["product.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["user.id"],
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('shopping_cart')
op.drop_table('review')
op.drop_table('like_history')
op.drop_table('user')
op.drop_table('product')
op.drop_table("shopping_cart")
op.drop_table("review")
op.drop_table("like_history")
op.drop_table("user")
op.drop_table("product")
# ### end Alembic commands ###
Loading

0 comments on commit 2655be2

Please sign in to comment.