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.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship, backref
|
||||
|
||||
from models.base import BaseModel
|
||||
from models.mixins import SoftDeleteMixin, CreatedAtMixin, IdMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Status, Board, DealStatusHistory
|
||||
from modules.clients.models import Client
|
||||
|
||||
|
||||
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||
@ -33,3 +34,11 @@ class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||
cascade="all, delete-orphan",
|
||||
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_not_found_msg = "Клиент не найден"
|
||||
|
||||
def _process_get_all_stmt(self, stmt: Select) -> Select:
|
||||
return stmt.where(Client.is_deleted.is_(False)).order_by(Client.created_at)
|
||||
def _process_get_all_stmt_with_args(
|
||||
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:
|
||||
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 modules.clients.schemas.client import *
|
||||
@ -14,8 +14,9 @@ router = APIRouter(tags=["client"])
|
||||
)
|
||||
async def get_clients(
|
||||
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(
|
||||
|
||||
@ -22,6 +22,7 @@ class CreateClientSchema(BaseSchema):
|
||||
|
||||
class ClientSchema(CreateClientSchema):
|
||||
id: int
|
||||
is_deleted: bool = False
|
||||
|
||||
|
||||
class UpdateClientSchema(BaseSchema):
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from modules.clients.schemas.client import ClientSchema
|
||||
from schemas.base import BaseSchema, BaseResponse, PaginationInfoSchema
|
||||
from schemas.board import BoardSchema
|
||||
from schemas.status import StatusSchema
|
||||
@ -16,6 +17,7 @@ class DealSchema(BaseSchema):
|
||||
status: StatusSchema
|
||||
board: BoardSchema
|
||||
created_at: datetime
|
||||
client: Optional[ClientSchema] = None
|
||||
|
||||
|
||||
class CreateDealSchema(BaseSchema):
|
||||
@ -23,6 +25,7 @@ class CreateDealSchema(BaseSchema):
|
||||
board_id: int
|
||||
lexorank: str
|
||||
status_id: int
|
||||
client_id: Optional[int] = None
|
||||
|
||||
|
||||
class UpdateDealSchema(BaseSchema):
|
||||
@ -30,6 +33,7 @@ class UpdateDealSchema(BaseSchema):
|
||||
lexorank: Optional[str] = None
|
||||
board_id: Optional[int] = None
|
||||
status_id: Optional[int] = None
|
||||
client: Optional[ClientSchema] = None
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
Reference in New Issue
Block a user