finish for init core
This commit is contained in:
27
fuware/schemas/fuware_model.py
Normal file
27
fuware/schemas/fuware_model.py
Normal file
@ -0,0 +1,27 @@
|
||||
from typing import ClassVar, Protocol, TypeVar
|
||||
from humps import camelize
|
||||
from enum import Enum
|
||||
from pydantic import UUID4, BaseModel, ConfigDict
|
||||
|
||||
T = TypeVar("T", bound=BaseModel)
|
||||
|
||||
class SearchType(Enum):
|
||||
fuzzy = "fuzzy"
|
||||
tokenized = "tokenized"
|
||||
|
||||
class FuwareModel(BaseModel):
|
||||
_searchable_properties: ClassVar[list[str]] = []
|
||||
"""
|
||||
Searchable properties for the search API.
|
||||
The first property will be used for sorting (order_by)
|
||||
"""
|
||||
model_config = ConfigDict(alias_generator=camelize, populate_by_name=True)
|
||||
|
||||
def cast(self, cls: type[T], **kwargs) -> T:
|
||||
"""
|
||||
Cast the current model to another with additional arguments. Useful for
|
||||
transforming DTOs into models that are saved to a database
|
||||
"""
|
||||
create_data = {field: getattr(self, field) for field in self.__fields__ if field in cls.__fields__}
|
||||
create_data.update(kwargs or {})
|
||||
return cls(**create_data)
|
1
fuware/schemas/user/__init__.py
Normal file
1
fuware/schemas/user/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .user import *
|
@ -1,8 +1,10 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from fastapi import Form
|
||||
|
||||
class UserBase(BaseModel):
|
||||
from fuware.schemas.fuware_model import FuwareModel
|
||||
|
||||
class UserBase(FuwareModel):
|
||||
username: str = Form(...)
|
||||
|
||||
class UserRequest(UserBase):
|
||||
@ -12,13 +14,11 @@ class UserCreate(UserRequest):
|
||||
password: str = Form(...)
|
||||
name: str
|
||||
|
||||
class User(UserBase):
|
||||
class PrivateUser(UserBase):
|
||||
id: str
|
||||
name: str
|
||||
is_admin: bool
|
||||
is_lock: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
Reference in New Issue
Block a user