mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
feat(backend): update consistent Pydantic v2 use everywhere
This commit is contained in:
@@ -1,23 +1,16 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, ConfigDict
|
||||||
try:
|
|
||||||
# Pydantic v2
|
|
||||||
from pydantic import ConfigDict # type: ignore
|
|
||||||
_HAS_V2 = True
|
|
||||||
except Exception: # pragma: no cover
|
|
||||||
_HAS_V2 = False
|
|
||||||
|
|
||||||
class CategoryBase(BaseModel):
|
class CategoryBase(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class CategoryCreate(CategoryBase):
|
class CategoryCreate(CategoryBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CategoryRead(CategoryBase):
|
class CategoryRead(CategoryBase):
|
||||||
id: int
|
id: int
|
||||||
if _HAS_V2:
|
model_config = ConfigDict(from_attributes=True)
|
||||||
model_config = ConfigDict(from_attributes=True) # type: ignore
|
|
||||||
else: # Pydantic v1 fallback
|
|
||||||
class Config: # type: ignore
|
|
||||||
orm_mode = True
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
class TransactionBase(BaseModel):
|
class TransactionBase(BaseModel):
|
||||||
amount: float = Field(..., gt=-1e18, lt=1e18)
|
amount: float = Field(..., gt=-1e18, lt=1e18)
|
||||||
@@ -17,5 +18,4 @@ class TransactionRead(TransactionBase):
|
|||||||
id: int
|
id: int
|
||||||
category_ids: List[int] = []
|
category_ids: List[int] = []
|
||||||
|
|
||||||
class Config:
|
model_config = ConfigDict(from_attributes=True)
|
||||||
from_attributes = True
|
|
||||||
|
|||||||
Reference in New Issue
Block a user