[feat] negodata/backend: 카드 도메인 CRUD 추가 + 견적·auth 보강

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 4.8 committed 2026-06-18 11:00:15 +09:00
1 parent 1fef405e88
commit e7660b10ac
11 files changed
+608 -31

No files matched your search

+100 -18
View File
@@ -3,12 +3,16 @@ import uuid
from fastapi import Depends
from common.database.db_session_manager import DB_SESSION_MNG
from common.database.model.models import quotations
from common.database.model.models import quotations, sessions, chats
from common.enums import DBWRType, ErrorType
from common.models.gmodel import PageParams
from crud.quotation_crud import IQuotationCRUD, QuotationCRUD
from router.v1.quotation.protocol import (
AsyncJob,
ChatMessageData,
QuotationCardData,
QuotationData,
SessionData,
Res_CreateQuotation,
Res_DeleteQuotation,
Res_Quotation,
@@ -42,14 +46,13 @@ class QuotationService:
return ErrorType.QUOTATION_NOT_FOUND, None
return ErrorType.SUCCESS, quotation
async def list_quotations(self, status, type_, start_from, start_to, page: int, size: int) -> Res_QuotationList:
res = Res_QuotationList(page=page, size=size)
skip = (page - 1) * size
async def list_quotations(self, status, type_, start_from, start_to, pg: PageParams) -> Res_QuotationList:
res = Res_QuotationList(page=pg.page, size=pg.size)
err_type, rows, total = await DB_SESSION_MNG.execute_lambda(
quotations.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.search(s, status, type_, start_from, start_to, skip, size),
lambda s: self.quotation_crud.search(s, status, type_, start_from, start_to, pg.skip, pg.size),
)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
@@ -154,31 +157,110 @@ class QuotationService:
return res
async def list_sessions(self, qt_id: str) -> Res_QuotationSessions:
# sessions 모델 미존재 — 존재 검증 후 빈 목록 반환(스텁).
res = Res_QuotationSessions()
err_type, quotation = await self._fetch(uuid.UUID(qt_id))
qt_uuid = uuid.UUID(qt_id)
err_type, quotation = await self._fetch(qt_uuid)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
err_type, rows = await DB_SESSION_MNG.execute_lambda(
sessions.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.list_sessions(s, qt_uuid),
)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
res.qt_id = quotation.qt_id
res.sessions = []
res.total = 0
# sessions.quotation_id → SessionData.qt_id 로 명시 매핑(컬럼명 불일치).
res.sessions = [
SessionData(
session_id=r.session_id,
qt_id=r.quotation_id,
supplier_id=r.supplier_id,
item_id=r.item_id,
qt_number=r.qt_number,
qt_round=r.qt_round,
qt_type=r.qt_type,
target_price=r.target_price,
status=r.status,
bid_price=r.bid_price,
bid_at=r.bid_at,
end_time=r.end_time,
reject_reason=r.reject_reason,
reject_price=r.reject_price,
reject_delivery_type=r.reject_delivery_type,
)
for r in rows
]
res.total = len(res.sessions)
return res
async def list_chats(self, session_id: str) -> Res_SessionChat:
# chats 모델 미존재 — 빈 목록 반환(스텁).
res = Res_SessionChat()
res.session_id = uuid.UUID(session_id)
res.messages = []
return res
sess_uuid = uuid.UUID(session_id)
res.session_id = sess_uuid
async def list_cards(self, qt_id: str) -> Res_QuotationCards:
# quotation_cards 모델 미존재 — 존재 검증 후 빈 목록 반환(스텁).
res = Res_QuotationCards()
err_type, quotation = await self._fetch(uuid.UUID(qt_id))
err_type, rows = await DB_SESSION_MNG.execute_lambda(
chats.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.list_chats(s, sess_uuid),
)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
# chats.seq → ChatMessageData.index 로 매핑. indicator_value(Decimal) → float.
res.messages = [
ChatMessageData(
chat_id=r.chat_id,
session_id=r.session_id,
card_id=r.card_id,
index=r.seq,
sender=r.sender,
target_price=r.target_price,
card_used_yn=r.card_used_yn,
indicator_value=float(r.indicator_value) if r.indicator_value is not None else None,
card_type=r.card_type,
)
for r in rows
]
return res
async def list_cards(self, qt_id: str) -> Res_QuotationCards:
res = Res_QuotationCards()
qt_uuid = uuid.UUID(qt_id)
err_type, quotation = await self._fetch(qt_uuid)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
err_type, rows = await DB_SESSION_MNG.execute_lambda(
chats.DBType(),
DBWRType.DB_READ.value,
lambda s: self.quotation_crud.list_used_cards(s, qt_uuid),
)
if err_type != ErrorType.SUCCESS:
res.result.SetResult(err_type)
return res
res.qt_id = quotation.qt_id
res.cards = []
# rows = [(chat_row, nego_card_id, name, script), ...]. nego/wild 구분은 chats.card_type.
cards = []
for chat_row, nc_id, nc_name, nc_script in rows:
is_wild = chat_row.card_type == 2
cards.append(
QuotationCardData(
session_card_id=chat_row.chat_id,
qt_id=quotation.qt_id,
nego_card_id=None if is_wild else nc_id,
wild_card_id=nc_id if is_wild else None,
type=chat_row.card_type if chat_row.card_type is not None else 1,
name=nc_name,
script=nc_script,
)
)
res.cards = cards
return res