refactor: using optional keyword
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from models import Board
|
||||
@ -13,7 +15,7 @@ class BoardRepository(BaseRepository):
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def get_by_id(self, board_id: int) -> Board | None:
|
||||
async def get_by_id(self, board_id: int) -> Optional[Board]:
|
||||
stmt = select(Board).where(Board.id == board_id, Board.is_deleted.is_(False))
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from models import Deal
|
||||
@ -11,7 +13,7 @@ class DealRepository(BaseRepository):
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def get_by_id(self, deal_id: int) -> Deal | None:
|
||||
async def get_by_id(self, deal_id: int) -> Optional[Deal]:
|
||||
stmt = select(Deal).where(Deal.id == deal_id, Deal.is_deleted.is_(False))
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from models import Status
|
||||
@ -7,14 +9,13 @@ from schemas.status import UpdateStatusSchema
|
||||
|
||||
class StatusRepository(BaseRepository):
|
||||
async def get_all(self, board_id: int) -> list[Status]:
|
||||
stmt = (
|
||||
select(Status)
|
||||
.where(Status.is_deleted.is_(False), Status.board_id == board_id)
|
||||
stmt = select(Status).where(
|
||||
Status.is_deleted.is_(False), Status.board_id == board_id
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def get_by_id(self, status_id: int) -> Status | None:
|
||||
async def get_by_id(self, status_id: int) -> Optional[Status]:
|
||||
stmt = select(Status).where(
|
||||
Status.id == status_id, Status.is_deleted.is_(False)
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import Self
|
||||
from typing import Self, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic.alias_generators import to_camel
|
||||
@ -36,8 +36,8 @@ class BaseResponse(BaseSchema):
|
||||
|
||||
|
||||
class PaginationSchema(BaseSchema):
|
||||
page: int | None = None
|
||||
items_per_page: int | None = None
|
||||
page: Optional[int] = None
|
||||
items_per_page: Optional[int] = None
|
||||
|
||||
|
||||
class PaginationInfoSchema(BaseSchema):
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from schemas.base import BaseSchema, BaseResponse
|
||||
|
||||
|
||||
@ -14,8 +16,8 @@ class BoardSchema(BaseBoardSchema):
|
||||
|
||||
|
||||
class UpdateBoardSchema(BaseSchema):
|
||||
name: str | None = None
|
||||
lexorank: str | None = None
|
||||
name: Optional[str] = None
|
||||
lexorank: Optional[str] = None
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from schemas.base import BaseSchema, BaseResponse
|
||||
|
||||
|
||||
@ -15,9 +17,9 @@ class DealSchema(BaseDealSchema):
|
||||
|
||||
|
||||
class UpdateDealSchema(BaseSchema):
|
||||
name: str | None = None
|
||||
lexorank: str | None = None
|
||||
status_id: int | None = None
|
||||
name: Optional[str] = None
|
||||
lexorank: Optional[str] = None
|
||||
status_id: Optional[int] = None
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from schemas.base import BaseSchema, BaseResponse
|
||||
|
||||
|
||||
@ -14,8 +16,8 @@ class StatusSchema(BaseStatusSchema):
|
||||
|
||||
|
||||
class UpdateStatusSchema(BaseSchema):
|
||||
name: str | None = None
|
||||
lexorank: str | None = None
|
||||
name: Optional[str] = None
|
||||
lexorank: Optional[str] = None
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
from typing import Optional
|
||||
|
||||
from schemas.base import PaginationSchema
|
||||
|
||||
|
||||
async def pagination_parameters(
|
||||
page: int | None = None, items_per_page: int | None = None
|
||||
page: Optional[int] = None, items_per_page: Optional[int] = None
|
||||
) -> PaginationSchema:
|
||||
return PaginationSchema(page=page, items_per_page=items_per_page)
|
||||
|
||||
|
||||
def is_valid_pagination(pagination: PaginationSchema | None) -> bool:
|
||||
def is_valid_pagination(pagination: Optional[PaginationSchema]) -> bool:
|
||||
if not pagination:
|
||||
return False
|
||||
return all(
|
||||
|
||||
Reference in New Issue
Block a user