feat: add pydantic schemas for location API
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0
app/schemas/__init__.py
Normal file
0
app/schemas/__init__.py
Normal file
7
app/schemas/common.py
Normal file
7
app/schemas/common.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorResponse(BaseModel):
|
||||||
|
error_code: str
|
||||||
|
message: str
|
||||||
|
detail: dict | None = None
|
||||||
39
app/schemas/location.py
Normal file
39
app/schemas/location.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from pydantic import BaseModel, field_validator
|
||||||
|
|
||||||
|
ZONGPAI_PATTERN = re.compile(r"^(\d{2}(B|C|T)\d+|\d{2}(BW|CW)\d{4})$")
|
||||||
|
LOCATION_NORMAL_PATTERN = re.compile(r"^[A-Z]+\d+-\d+-\d+$")
|
||||||
|
LOCATION_TRANS_PATTERN = re.compile(r"^TRANS-\d+")
|
||||||
|
|
||||||
|
|
||||||
|
class LocationRequest(BaseModel):
|
||||||
|
zongpai_no: str
|
||||||
|
location_code: str
|
||||||
|
|
||||||
|
@field_validator("zongpai_no")
|
||||||
|
@classmethod
|
||||||
|
def validate_zongpai_no(cls, v: str) -> str:
|
||||||
|
v = v.strip().upper()
|
||||||
|
if not ZONGPAI_PATTERN.match(v):
|
||||||
|
raise ValueError("INVALID_ZONGPAI")
|
||||||
|
return v
|
||||||
|
|
||||||
|
@field_validator("location_code")
|
||||||
|
@classmethod
|
||||||
|
def validate_location_code(cls, v: str) -> str:
|
||||||
|
v = v.strip().upper()
|
||||||
|
if not LOCATION_NORMAL_PATTERN.match(v) and not LOCATION_TRANS_PATTERN.match(v):
|
||||||
|
raise ValueError("INVALID_LOCATION")
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
class LocationResponse(BaseModel):
|
||||||
|
zongpai_no: str
|
||||||
|
location_code: str
|
||||||
|
created_at: str
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateLocationDetail(BaseModel):
|
||||||
|
existing_location: str
|
||||||
|
created_at: str
|
||||||
Reference in New Issue
Block a user