finish for init core

This commit is contained in:
2024-05-09 16:01:32 +00:00
parent ab1e864478
commit bc8815f40e
42 changed files with 520 additions and 214 deletions

View 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)

View File

@ -0,0 +1 @@
from .user import *

View File

@ -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)