-
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.
Merge pull request #8 from FinemechanicPub/dev
Update
- Loading branch information
Showing
26 changed files
with
857 additions
and
101 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,36 @@ | ||
"""Add Menu | ||
Revision ID: 1f37e3800cd9 | ||
Revises: 81641f63833f | ||
Create Date: 2024-08-24 02:39:40.192287 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '1f37e3800cd9' | ||
down_revision: Union[str, None] = '81641f63833f' | ||
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('menu', | ||
sa.Column('order', sa.SmallInteger(), nullable=False), | ||
sa.Column('title', sa.String(), nullable=False), | ||
sa.Column('query', sa.JSON(), nullable=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id', name=op.f('pk_menu')) | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('menu') | ||
# ### end Alembic commands ### |
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,59 @@ | ||
from fastapi import APIRouter, Depends, status | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.core.user import superuser | ||
from app.schemas.menu import MenuBase, MenuResponse, MenuUpdateRequest | ||
from app.repositories.menu import menu_repository | ||
from app.core.db import get_async_session | ||
from app.api.exceptions import MenuNotFoundException | ||
|
||
router = APIRouter(prefix="/main", tags=["Main"]) | ||
|
||
|
||
@router.get("/menu/", response_model=list[MenuResponse]) | ||
async def list_menu(session: AsyncSession = Depends(get_async_session)): | ||
return await menu_repository.list(session) | ||
|
||
|
||
@router.post( | ||
"/menu/", | ||
response_model=MenuResponse, | ||
response_model_exclude_none=True, | ||
status_code=status.HTTP_201_CREATED, | ||
dependencies=[Depends(superuser)], | ||
) | ||
async def create_menu( | ||
menu_data: MenuBase, | ||
session: AsyncSession = Depends(get_async_session), | ||
): | ||
return await menu_repository.create(session, menu_data) | ||
|
||
|
||
@router.patch( | ||
"/menu/{menu_id}/", | ||
response_model=MenuResponse, | ||
dependencies=[Depends(superuser)], | ||
) | ||
async def update_menu( | ||
menu_id: int, | ||
menu_data: MenuUpdateRequest, | ||
session: AsyncSession = Depends(get_async_session), | ||
): | ||
menu = await menu_repository.get(session, menu_id) | ||
if not menu: | ||
raise MenuNotFoundException | ||
return await menu_repository.update(session, menu, menu_data) | ||
|
||
|
||
@router.delete( | ||
"/menu/{menu_id}/", | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
dependencies=[Depends(superuser)], | ||
) | ||
async def delete_menu( | ||
menu_id: int, session: AsyncSession = Depends(get_async_session) | ||
): | ||
menu = await menu_repository.get(session, menu_id) | ||
if not menu: | ||
raise MenuNotFoundException | ||
await menu_repository.remove(session, menu) |
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 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 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,16 @@ | ||
from sqlalchemy import JSON, SmallInteger | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from app.models.base import Base | ||
|
||
|
||
class Menu(Base): | ||
order: Mapped[int] = mapped_column(SmallInteger) | ||
title: Mapped[str] | ||
query: Mapped[dict[str, str]] = mapped_column(JSON) | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"Menu(id={self.id}, title={self.title}, " | ||
f"query={self.query}, order={self.order})" | ||
) |
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 app.models.menu import Menu | ||
from app.repositories.repository import RepositoryBase | ||
|
||
|
||
class MenuRepository(RepositoryBase[Menu]): | ||
pass | ||
|
||
|
||
menu_repository = MenuRepository(Menu) |
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,20 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
|
||
class MenuBase(BaseModel): | ||
title: str = Field(..., min_length=1) | ||
query: dict[str, str | int] | ||
order: int = Field(..., ge=0) | ||
|
||
|
||
class MenuUpdateRequest(BaseModel): | ||
title: Optional[str] = Field(None, min_length=1) | ||
query: Optional[dict[str, str | int]] = Field(None) | ||
order: Optional[int] = Field(None, ge=0) | ||
|
||
|
||
class MenuResponse(MenuBase): | ||
id: int | ||
|
||
model_config = ConfigDict(from_attributes=True) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
Oops, something went wrong.