- item/supplier/quotation/quotation_setting CRUD·service·router 추가 - item protocol delivery_type str→int (ERD/스키마 SMALLINT 일치) - DeliveryType enum + 한글 라벨, 공용 GET /v1/enums (도메인 코드 메타데이터) - CompanyBrief → CompanyData 로 *Data 네이밍 통일 - CORS: WebServerConfig.client_url(단일) 도입 (config_models/router) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
import json
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from common.enums import ErrorType
|
|
|
|
|
|
class StructModel:
|
|
"""프로토콜/구조체 식별용 마커 클래스."""
|
|
|
|
pass
|
|
|
|
|
|
class ErrorInfo(BaseModel, StructModel):
|
|
"""모든 응답에 공통으로 실리는 결과 정보. result.success / code / desc 로 내려간다."""
|
|
|
|
success: Optional[bool] = True
|
|
code: Optional[int] = ErrorType.SUCCESS.value
|
|
desc: Optional[str] = ErrorType.SUCCESS.name
|
|
|
|
def SetResult(self, enum: ErrorType):
|
|
if enum is not None:
|
|
self.success = ErrorType.SUCCESS.value == enum.value
|
|
self.code = enum.value
|
|
self.desc = enum.name
|
|
|
|
|
|
# ---- Protocol 규약 -------------------------------------------------------
|
|
# 모든 통신 패킷은 WebPacketProtocol 을 상속한다.
|
|
# 요청 : Req_xxx (WebPacketProtocol)
|
|
# 응답 : Res_xxx (Res_WebPacketProtocol) - 항상 result 필드를 가진다.
|
|
# 각 라우터 폴더의 protocol.py 에 Req_/Res_ 를 정의한다.
|
|
class WebPacketProtocol(BaseModel, StructModel):
|
|
pass
|
|
|
|
|
|
class Req_WebPacketProtocol(WebPacketProtocol):
|
|
pass
|
|
|
|
|
|
class Res_WebPacketProtocol(WebPacketProtocol):
|
|
# default_factory 로 인스턴스마다 새 ErrorInfo 를 생성한다 (mutable default 공유 방지).
|
|
result: ErrorInfo = Field(default_factory=ErrorInfo)
|
|
msg: Optional[str] = None
|
|
|
|
|
|
class UserInfo(StructModel):
|
|
"""JWT subject 로 인코딩되는 유저 식별 정보."""
|
|
|
|
user_id: str # users.user_id (uuid) — 데이터 스코프 키
|
|
id: str # users.id (로그인 아이디) — get_me 재조회 키
|
|
company_id: str # users.company_id (uuid) — 멀티테넌트 스코프 키
|
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
super().__init__()
|
|
for dictionary in args:
|
|
for key in dictionary:
|
|
setattr(self, key, dictionary[key])
|
|
for key in kwargs:
|
|
setattr(self, key, kwargs[key])
|
|
|
|
def to_json(self) -> str:
|
|
return json.dumps(self.__dict__)
|