feat: client endpoints fixes for client tab in deal editor
This commit is contained in:
@ -1,13 +1,14 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from sqlalchemy import ForeignKey
|
from sqlalchemy import ForeignKey
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship, backref
|
||||||
|
|
||||||
from models.base import BaseModel
|
from models.base import BaseModel
|
||||||
from models.mixins import SoftDeleteMixin, CreatedAtMixin, IdMixin
|
from models.mixins import SoftDeleteMixin, CreatedAtMixin, IdMixin
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from models import Status, Board, DealStatusHistory
|
from models import Status, Board, DealStatusHistory
|
||||||
|
from modules.clients.models import Client
|
||||||
|
|
||||||
|
|
||||||
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||||
@ -33,3 +34,11 @@ class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
|||||||
cascade="all, delete-orphan",
|
cascade="all, delete-orphan",
|
||||||
lazy="noload",
|
lazy="noload",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# module client
|
||||||
|
client_id: Mapped[Optional[int]] = mapped_column(
|
||||||
|
ForeignKey("clients.id", ondelete="CASCADE"),
|
||||||
|
)
|
||||||
|
client: Mapped["Client"] = relationship(
|
||||||
|
backref=backref("deals", cascade="all, delete-orphan"), lazy="immediate"
|
||||||
|
)
|
||||||
|
|||||||
@ -17,8 +17,12 @@ class ClientRepository(
|
|||||||
entity_class = Client
|
entity_class = Client
|
||||||
entity_not_found_msg = "Клиент не найден"
|
entity_not_found_msg = "Клиент не найден"
|
||||||
|
|
||||||
def _process_get_all_stmt(self, stmt: Select) -> Select:
|
def _process_get_all_stmt_with_args(
|
||||||
return stmt.where(Client.is_deleted.is_(False)).order_by(Client.created_at)
|
self, stmt: Select, include_deleted: bool
|
||||||
|
) -> Select:
|
||||||
|
if not include_deleted:
|
||||||
|
stmt = stmt.where(Client.is_deleted.is_(False))
|
||||||
|
return stmt.order_by(Client.created_at)
|
||||||
|
|
||||||
async def create(self, data: CreateClientSchema) -> int:
|
async def create(self, data: CreateClientSchema) -> int:
|
||||||
details = ClientDetails(**data.details.model_dump())
|
details = ClientDetails(**data.details.model_dump())
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter, Path
|
from fastapi import APIRouter, Path, Query
|
||||||
|
|
||||||
from backend.dependecies import SessionDependency
|
from backend.dependecies import SessionDependency
|
||||||
from modules.clients.schemas.client import *
|
from modules.clients.schemas.client import *
|
||||||
@ -14,8 +14,9 @@ router = APIRouter(tags=["client"])
|
|||||||
)
|
)
|
||||||
async def get_clients(
|
async def get_clients(
|
||||||
session: SessionDependency,
|
session: SessionDependency,
|
||||||
|
include_deleted: bool = Query(alias="includeDeleted", default=False),
|
||||||
):
|
):
|
||||||
return await ClientService(session).get_all()
|
return await ClientService(session).get_all(include_deleted)
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
|
|||||||
@ -22,6 +22,7 @@ class CreateClientSchema(BaseSchema):
|
|||||||
|
|
||||||
class ClientSchema(CreateClientSchema):
|
class ClientSchema(CreateClientSchema):
|
||||||
id: int
|
id: int
|
||||||
|
is_deleted: bool = False
|
||||||
|
|
||||||
|
|
||||||
class UpdateClientSchema(BaseSchema):
|
class UpdateClientSchema(BaseSchema):
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from modules.clients.schemas.client import ClientSchema
|
||||||
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
||||||
from schemas.board import BoardSchema
|
from schemas.board import BoardSchema
|
||||||
from schemas.status import StatusSchema
|
from schemas.status import StatusSchema
|
||||||
@ -16,6 +17,7 @@ class DealSchema(BaseSchema):
|
|||||||
status: StatusSchema
|
status: StatusSchema
|
||||||
board: BoardSchema
|
board: BoardSchema
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
client: Optional[ClientSchema] = None
|
||||||
|
|
||||||
|
|
||||||
class CreateDealSchema(BaseSchema):
|
class CreateDealSchema(BaseSchema):
|
||||||
@ -23,6 +25,7 @@ class CreateDealSchema(BaseSchema):
|
|||||||
board_id: int
|
board_id: int
|
||||||
lexorank: str
|
lexorank: str
|
||||||
status_id: int
|
status_id: int
|
||||||
|
client_id: Optional[int] = None
|
||||||
|
|
||||||
|
|
||||||
class UpdateDealSchema(BaseSchema):
|
class UpdateDealSchema(BaseSchema):
|
||||||
@ -30,6 +33,7 @@ class UpdateDealSchema(BaseSchema):
|
|||||||
lexorank: Optional[str] = None
|
lexorank: Optional[str] = None
|
||||||
board_id: Optional[int] = None
|
board_id: Optional[int] = None
|
||||||
status_id: Optional[int] = None
|
status_id: Optional[int] = None
|
||||||
|
client: Optional[ClientSchema] = None
|
||||||
|
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user