[refactor] negodata/backend: 서비스 계층 입력을 dict→타입드 Req 패킷으로 통일
라우터가 req.model_dump(exclude_unset=True)로 dict를 만들어 넘기던 것을 req(Req_*) 객체 그대로 전달하도록 변경. 서비스 시그니처를 전부 타입드로 통일. - create 5개(quotation/card/item/supplier/quotation_setting): ORM은 명시 kwargs 조립(item만 컬럼 16개라 model_dump 펼침). 경계 검증·타입 유지, **data 결합 제거. - update 4개: 서비스가 req 받아 내부에서 model_dump(exclude_unset=True) 생성 후 CRUD(dict)로 전달 — 공식 PATCH 메커니즘 유지. - 서비스 계층 data: dict 시그니처 0개. CRUD는 dict 유지(의도). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fd2e5c1cc2
commit
d47476dc04
10 files changed
+97
-79
No files matched your search
@@ -8,7 +8,15 @@ from common.enums import DBWRType, ErrorType
|
||||
from common.logger import LOG
|
||||
from common.models.gmodel import PageParams
|
||||
from crud.supplier_crud import ISupplierCRUD, SupplierCRUD
|
||||
from router.v1.supplier.protocol import Res_CheckCodes, Res_DeleteSupplier, Res_Supplier, Res_SupplierList, SupplierData
|
||||
from router.v1.supplier.protocol import (
|
||||
Req_CreateSupplier,
|
||||
Req_UpdateSupplier,
|
||||
Res_CheckCodes,
|
||||
Res_DeleteSupplier,
|
||||
Res_Supplier,
|
||||
Res_SupplierList,
|
||||
SupplierData,
|
||||
)
|
||||
|
||||
|
||||
class SupplierService:
|
||||
@@ -70,12 +78,12 @@ class SupplierService:
|
||||
res.existing = list(existing)
|
||||
return res
|
||||
|
||||
async def create_supplier(self, company_id: str, user_id: str, data: dict) -> Res_Supplier:
|
||||
async def create_supplier(self, company_id: str, user_id: str, req: Req_CreateSupplier) -> Res_Supplier:
|
||||
res = Res_Supplier()
|
||||
company_uuid = uuid.UUID(company_id)
|
||||
|
||||
# DB 중복코드 검증: 같은 회사에 동일 code 가 이미 있으면 거부(프론트는 받아온 목록만 보므로 여기서 최종 차단).
|
||||
code = data.get("code")
|
||||
code = req.code
|
||||
if code:
|
||||
dup_err, exists = await DB_SESSION_MNG.execute_lambda(
|
||||
suppliers.DBType(),
|
||||
@@ -89,7 +97,16 @@ class SupplierService:
|
||||
res.result.SetResult(ErrorType.SUPPLIER_CODE_DUPLICATE)
|
||||
return res
|
||||
|
||||
supplier = suppliers(**data, company_id=company_uuid, user_id=uuid.UUID(user_id))
|
||||
supplier = suppliers(
|
||||
company_id=company_uuid,
|
||||
user_id=uuid.UUID(user_id),
|
||||
name=req.name,
|
||||
code=req.code,
|
||||
manager_name=req.manager_name,
|
||||
manager_email=req.manager_email,
|
||||
manager_contact_number=req.manager_contact_number,
|
||||
priority=req.priority,
|
||||
)
|
||||
err_type = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[suppliers.DBType()],
|
||||
[lambda s: self.supplier_crud.add_supplier(s, supplier)],
|
||||
@@ -100,10 +117,11 @@ class SupplierService:
|
||||
# 서버 기본값(created_at/updated_at)은 insert 후 객체에 실리지 않으므로 재조회한다.
|
||||
return await self.get_supplier(company_id, str(supplier.supplier_id))
|
||||
|
||||
async def update_supplier(self, company_id: str, supplier_id: str, data: dict) -> Res_Supplier:
|
||||
async def update_supplier(self, company_id: str, supplier_id: str, req: Req_UpdateSupplier) -> Res_Supplier:
|
||||
res = Res_Supplier()
|
||||
company_uuid = uuid.UUID(company_id)
|
||||
supplier_uuid = uuid.UUID(supplier_id)
|
||||
data = req.model_dump(exclude_unset=True)
|
||||
|
||||
# 소유권 확인
|
||||
err_type, _ = await self._fetch_owned(company_uuid, supplier_uuid)
|
||||
|
||||
Reference in new issue
Block a user