Updated vendor API to correct issues - Implement new UI
This commit is contained in:
@@ -60,6 +60,7 @@ class Vendor(BaseModel):
|
||||
registered: datetime = Field(description="When the vendor was registered in the database. UTC Timezone.")
|
||||
name: str = Field(max_length=64, description="Vendor name.", example="Polymaker")
|
||||
comment: Optional[str] = Field(max_length=1024, description="Free text comment about this vendor.", example="")
|
||||
empty_spool_weight: Optional[float] = Field(gt=0, description="The empty spool weight, in grams.", example=140)
|
||||
extra: dict[str, str] = Field(
|
||||
description=(
|
||||
"Extra fields for this vendor. All values are JSON-encoded data. "
|
||||
@@ -75,6 +76,7 @@ class Vendor(BaseModel):
|
||||
registered=item.registered,
|
||||
name=item.name,
|
||||
comment=item.comment,
|
||||
empty_spool_weight=item.empty_spool_weight,
|
||||
extra={field.key: field.value for field in item.extra},
|
||||
)
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@ class VendorParameters(BaseModel):
|
||||
description="Free text comment about this vendor.",
|
||||
example="",
|
||||
)
|
||||
empty_spool_weight: Optional[float] = Field(
|
||||
ge=0,
|
||||
description="The weight of an empty spool.",
|
||||
example=200,
|
||||
)
|
||||
extra: Optional[dict[str, str]] = Field(
|
||||
None,
|
||||
description="Extra fields for this vendor.",
|
||||
@@ -41,11 +46,6 @@ class VendorParameters(BaseModel):
|
||||
|
||||
class VendorUpdateParameters(VendorParameters):
|
||||
name: Optional[str] = Field(max_length=64, description="Vendor name.", example="Polymaker")
|
||||
comment: Optional[str] = Field(
|
||||
max_length=1024,
|
||||
description="Free text comment about this vendor.",
|
||||
example="",
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -190,6 +190,7 @@ async def create( # noqa: ANN201
|
||||
db=db,
|
||||
name=body.name,
|
||||
comment=body.comment,
|
||||
empty_spool_weight=body.empty_spool_weight,
|
||||
extra=body.extra,
|
||||
)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ async def create(
|
||||
db: AsyncSession,
|
||||
name: Optional[str] = None,
|
||||
comment: Optional[str] = None,
|
||||
empty_spool_weight: Optional[float] = None,
|
||||
extra: Optional[dict[str, str]] = None,
|
||||
) -> models.Vendor:
|
||||
"""Add a new vendor to the database."""
|
||||
@@ -26,6 +27,7 @@ async def create(
|
||||
name=name,
|
||||
registered=datetime.utcnow().replace(microsecond=0),
|
||||
comment=comment,
|
||||
empty_spool_weight=empty_spool_weight,
|
||||
extra=[models.VendorField(key=k, value=v) for k, v in (extra or {}).items()],
|
||||
)
|
||||
db.add(vendor)
|
||||
|
||||
Reference in New Issue
Block a user