first commit
This commit is contained in:
37
backend/app/schemas/__init__.py
Normal file
37
backend/app/schemas/__init__.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Pydantic schemas for API request/response."""
|
||||
|
||||
from app.schemas.case import (
|
||||
CaseCreate,
|
||||
CaseUpdate,
|
||||
CaseResponse,
|
||||
CaseListResponse,
|
||||
)
|
||||
from app.schemas.screenshot import (
|
||||
ScreenshotResponse,
|
||||
ScreenshotListResponse,
|
||||
)
|
||||
from app.schemas.transaction import (
|
||||
TransactionCreate,
|
||||
TransactionResponse,
|
||||
TransactionListResponse,
|
||||
TransactionExtractItem,
|
||||
)
|
||||
from app.schemas.analysis import (
|
||||
AnalysisSummaryResponse,
|
||||
FlowGraphResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"CaseCreate",
|
||||
"CaseUpdate",
|
||||
"CaseResponse",
|
||||
"CaseListResponse",
|
||||
"ScreenshotResponse",
|
||||
"ScreenshotListResponse",
|
||||
"TransactionCreate",
|
||||
"TransactionResponse",
|
||||
"TransactionListResponse",
|
||||
"TransactionExtractItem",
|
||||
"AnalysisSummaryResponse",
|
||||
"FlowGraphResponse",
|
||||
]
|
||||
35
backend/app/schemas/analysis.py
Normal file
35
backend/app/schemas/analysis.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Analysis response schemas."""
|
||||
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class AppSummary(BaseModel):
|
||||
in_amount: Decimal
|
||||
out_amount: Decimal
|
||||
|
||||
|
||||
class AnalysisSummaryResponse(BaseModel):
|
||||
total_out: Decimal
|
||||
total_in: Decimal
|
||||
net_loss: Decimal
|
||||
by_app: dict[str, AppSummary]
|
||||
counterparty_count: int
|
||||
|
||||
|
||||
class FlowNode(BaseModel):
|
||||
id: str
|
||||
label: str
|
||||
type: str | None = None # victim_app | counterparty
|
||||
|
||||
|
||||
class FlowEdge(BaseModel):
|
||||
source: str
|
||||
target: str
|
||||
amount: Decimal
|
||||
count: int = 1
|
||||
|
||||
|
||||
class FlowGraphResponse(BaseModel):
|
||||
nodes: list[FlowNode]
|
||||
edges: list[FlowEdge]
|
||||
36
backend/app/schemas/case.py
Normal file
36
backend/app/schemas/case.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Case schemas."""
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class CaseBase(BaseModel):
|
||||
case_number: str
|
||||
victim_name: str
|
||||
description: str = ""
|
||||
|
||||
|
||||
class CaseCreate(CaseBase):
|
||||
pass
|
||||
|
||||
|
||||
class CaseUpdate(BaseModel):
|
||||
case_number: str | None = None
|
||||
victim_name: str | None = None
|
||||
description: str | None = None
|
||||
total_loss: Decimal | None = None
|
||||
status: str | None = None
|
||||
|
||||
|
||||
class CaseResponse(CaseBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
total_loss: Decimal
|
||||
status: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class CaseListResponse(BaseModel):
|
||||
items: list[CaseResponse]
|
||||
18
backend/app/schemas/screenshot.py
Normal file
18
backend/app/schemas/screenshot.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Screenshot schemas."""
|
||||
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class ScreenshotResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
case_id: int
|
||||
filename: str
|
||||
file_path: str
|
||||
status: str
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class ScreenshotListResponse(BaseModel):
|
||||
items: list[ScreenshotResponse]
|
||||
51
backend/app/schemas/transaction.py
Normal file
51
backend/app/schemas/transaction.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Transaction schemas."""
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class TransactionBase(BaseModel):
|
||||
app_source: str
|
||||
transaction_type: str
|
||||
amount: Decimal
|
||||
currency: str = "CNY"
|
||||
counterparty_name: str | None = None
|
||||
counterparty_account: str | None = None
|
||||
order_number: str | None = None
|
||||
transaction_time: datetime | None = None
|
||||
remark: str | None = None
|
||||
confidence: str = "medium"
|
||||
|
||||
|
||||
class TransactionCreate(TransactionBase):
|
||||
case_id: int
|
||||
screenshot_id: int
|
||||
raw_text: str | None = None
|
||||
|
||||
|
||||
class TransactionResponse(TransactionBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
case_id: int
|
||||
screenshot_id: int
|
||||
raw_text: str | None = None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class TransactionListResponse(BaseModel):
|
||||
items: list[TransactionResponse]
|
||||
|
||||
|
||||
class TransactionExtractItem(BaseModel):
|
||||
"""Single item as returned by LLM extraction (before DB insert)."""
|
||||
app_source: str
|
||||
transaction_type: str
|
||||
amount: Decimal
|
||||
currency: str = "CNY"
|
||||
counterparty_name: str | None = None
|
||||
counterparty_account: str | None = None
|
||||
order_number: str | None = None
|
||||
transaction_time: datetime | None = None
|
||||
remark: str | None = None
|
||||
confidence: str = "medium"
|
||||
Reference in New Issue
Block a user