Adding ISOThread and UNC Thread
This commit is contained in:
1 parent
9285a021c0
commit
35e8a61b1d
22 files changed
+796
-3
No files matched your search
@@ -0,0 +1,23 @@
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class IsoThreadBase(BaseModel):
|
||||
diameter_mm: float = Field(..., gt=0, description="Nominal diameter in mm")
|
||||
pitch_mm: float = Field(..., gt=0, description="Thread pitch in mm")
|
||||
depth_mm: float | None = Field(None, gt=0, description="Thread depth in mm")
|
||||
|
||||
|
||||
class IsoThreadCreate(IsoThreadBase):
|
||||
pass
|
||||
|
||||
|
||||
class IsoThreadUpdate(BaseModel):
|
||||
diameter_mm: float | None = Field(None, gt=0)
|
||||
pitch_mm: float | None = Field(None, gt=0)
|
||||
depth_mm: float | None = Field(None, gt=0)
|
||||
|
||||
|
||||
class IsoThreadRead(IsoThreadBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
@@ -0,0 +1,52 @@
|
||||
import re
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
from app.models.unc_thread import UncSeries
|
||||
|
||||
_FRACTION_RE = re.compile(r"^\d+(/\d+)?(-\d+/\d+)?$")
|
||||
|
||||
|
||||
class UncThreadBase(BaseModel):
|
||||
diameter_fraction: str = Field(
|
||||
...,
|
||||
description='Nominal diameter as a fractional inch string, e.g. "1/4", "3/8", "1-1/2"',
|
||||
)
|
||||
tpi: int = Field(..., gt=0, description="Threads per inch")
|
||||
series: UncSeries
|
||||
depth_in: float | None = Field(None, gt=0, description="Thread depth in inches")
|
||||
|
||||
@field_validator("diameter_fraction")
|
||||
@classmethod
|
||||
def validate_fraction(cls, v: str) -> str:
|
||||
if not _FRACTION_RE.match(v):
|
||||
raise ValueError(
|
||||
'diameter_fraction must be a fractional inch string, e.g. "1/4", "3/8", "1-1/2"'
|
||||
)
|
||||
return v
|
||||
|
||||
|
||||
class UncThreadCreate(UncThreadBase):
|
||||
pass
|
||||
|
||||
|
||||
class UncThreadUpdate(BaseModel):
|
||||
diameter_fraction: str | None = None
|
||||
tpi: int | None = Field(None, gt=0)
|
||||
series: UncSeries | None = None
|
||||
depth_in: float | None = Field(None, gt=0)
|
||||
|
||||
@field_validator("diameter_fraction")
|
||||
@classmethod
|
||||
def validate_fraction(cls, v: str | None) -> str | None:
|
||||
if v is not None and not _FRACTION_RE.match(v):
|
||||
raise ValueError(
|
||||
'diameter_fraction must be a fractional inch string, e.g. "1/4", "3/8", "1-1/2"'
|
||||
)
|
||||
return v
|
||||
|
||||
|
||||
class UncThreadRead(UncThreadBase):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
Reference in new issue
Block a user