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