Done setup template
This commit is contained in:
2
backend/schemas/__init__.py
Normal file
2
backend/schemas/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .common import *
|
||||
from .user import *
|
8
backend/schemas/common.py
Normal file
8
backend/schemas/common.py
Normal 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
|
27
backend/schemas/fuware_model.py
Normal file
27
backend/schemas/fuware_model.py
Normal 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)
|
1
backend/schemas/user/__init__.py
Normal file
1
backend/schemas/user/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .user import *
|
40
backend/schemas/user/user.py
Normal file
40
backend/schemas/user/user.py
Normal 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
|
Reference in New Issue
Block a user