Refactoring Hub Firms routes
This commit is contained in:
@@ -5,25 +5,29 @@ from pymongo import IndexModel
|
||||
from hub.core import CrudDocument
|
||||
|
||||
class Firm(CrudDocument):
|
||||
name: str = Field()
|
||||
instance: str = Field()
|
||||
firm: str = Field()
|
||||
owner: PydanticObjectId = Field()
|
||||
|
||||
@classmethod
|
||||
def get_by_name(cls, instance, firm):
|
||||
return cls.find_one({"instance": instance, "firm": firm})
|
||||
|
||||
def compute_label(self) -> str:
|
||||
return self.name
|
||||
return f"{self.instance} / {self.firm}"
|
||||
|
||||
class Settings:
|
||||
indexes = [
|
||||
IndexModel(["name", "instance"], unique=True),
|
||||
IndexModel(["instance", "firm"], unique=True),
|
||||
]
|
||||
|
||||
class FirmRead(BaseModel):
|
||||
instance: str = Field()
|
||||
name: str = Field()
|
||||
firm: str = Field()
|
||||
|
||||
class FirmCreate(FirmRead):
|
||||
instance: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
||||
name: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
||||
firm: str = Field(max_length=32, min_length=3, pattern="^[0-9a-z-]+$")
|
||||
|
||||
class FirmUpdate(BaseModel):
|
||||
owner: PydanticObjectId = Field()
|
||||
|
||||
Reference in New Issue
Block a user