Done setup template

This commit is contained in:
2024-06-01 12:34:20 +00:00
parent 71d4afcc5e
commit 449a5f644f
104 changed files with 313 additions and 256 deletions

View File

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

View File

@ -0,0 +1,8 @@
from typing import Generic, TypeVar
from pydantic import BaseModel
T = TypeVar('T')
class ReturnValue(BaseModel, Generic[T]):
status: int
data: T

View File

@ -0,0 +1,27 @@
from typing import ClassVar, TypeVar
from humps import camelize
from enum import Enum
from pydantic import 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

@ -0,0 +1,40 @@
from datetime import datetime
from uuid import UUID
from pydantic import ConfigDict
from fastapi import Form
from backend.schemas.fuware_model import FuwareModel
class UserBase(FuwareModel):
username: str = Form(...)
class UserRequest(UserBase):
password: str = Form(...)
class UserCreate(UserRequest):
name: str
class UserSeeds(UserCreate):
is_admin: bool
is_lock: bool
class PrivateUser(UserBase):
id: UUID
name: str
is_admin: bool
is_lock: bool
created_at: datetime
updated_at: datetime
model_config = ConfigDict(from_attributes=True)
class ProfileResponse(UserBase):
name: str
is_admin: bool
created_at: datetime
updated_at: datetime
model_config = ConfigDict(from_attributes=True)
class LoginResponse(FuwareModel):
access_token: str
exp: int
name: str