Filaments can now be created

This commit is contained in:
Donkie
2023-04-01 22:51:36 +02:00
parent 35fdd23ec0
commit 2fa91b0632
11 changed files with 246 additions and 44 deletions

View File

@@ -5,12 +5,23 @@ from typing import Optional
from pydantic import BaseModel, Field
from spoolson.database import models
class Vendor(BaseModel):
id: int = Field(description="Unique internal ID of this vendor.")
name: str = Field(max_length=64, description="Vendor name.")
comment: Optional[str] = Field(max_length=1024, description="Free text comment about this vendor.")
@staticmethod
def from_db(item: models.Vendor) -> "Vendor":
"""Create a new Pydantic vendor object from a database vendor object."""
return Vendor(
id=item.id,
name=item.name,
comment=item.comment,
)
class Filament(BaseModel):
id: int = Field(description="Unique internal ID of this filament type.")
@@ -31,6 +42,23 @@ class Filament(BaseModel):
article_number: Optional[str] = Field(max_length=64, description="Vendor article number, e.g. EAN, QR code, etc.")
comment: Optional[str] = Field(max_length=1024, description="Free text comment about this filament type.")
@staticmethod
def from_db(item: models.Filament) -> "Filament":
"""Create a new Pydantic filament object from a database filament object."""
return Filament(
id=item.id,
name=item.name,
vendor=Vendor.from_db(item.vendor) if item.vendor is not None else None,
material=item.material,
price=item.price,
density=item.density,
diameter=item.diameter,
weight=item.weight,
spool_weight=item.spool_weight,
article_number=item.article_number,
comment=item.comment,
)
class Spool(BaseModel):
id: int = Field(description="Unique internal ID of this spool of filament.")
@@ -42,3 +70,18 @@ class Spool(BaseModel):
location: Optional[str] = Field(max_length=64, description="Where this spool can be found.")
lot_nr: Optional[str] = Field(max_length=64, description="Vendor manufacturing lot/batch number of the spool.")
comment: Optional[str] = Field(max_length=1024, description="Free text comment about this specific spool.")
@staticmethod
def from_db(item: models.Spool) -> "Spool":
"""Create a new Pydantic spool object from a database spool object."""
return Spool(
id=item.id,
registered=item.registered,
first_used=item.first_used,
last_used=item.last_used,
filament=Filament.from_db(item.filament),
weight=item.weight,
location=item.location,
lot_nr=item.lot_nr,
comment=item.comment,
)