fix: Update Pydantic models to use ConfigDict instead of deprecated class-based config
Replace deprecated class Config with model_config = ConfigDict() to fix Pydantic v2 deprecation warnings
This commit is contained in:
parent
d6eeb9a079
commit
6ebf2d4b45
@ -1,7 +1,7 @@
|
|||||||
from fastapi import FastAPI, HTTPException, Header, Depends
|
from fastapi import FastAPI, HTTPException, Header, Depends
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, ConfigDict
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@ -46,31 +46,31 @@ app.add_middleware(
|
|||||||
|
|
||||||
# Pydantic Models for API
|
# Pydantic Models for API
|
||||||
class UserResponse(BaseModel):
|
class UserResponse(BaseModel):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
username: str
|
username: str
|
||||||
email: str
|
email: str
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
class Config:
|
|
||||||
from_attributes = True
|
|
||||||
|
|
||||||
class UserRegister(BaseModel):
|
class UserRegister(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
email: str
|
email: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
class UserLogin(BaseModel):
|
class UserLogin(BaseModel):
|
||||||
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
|
|
||||||
username_or_email: str = Field(..., alias='usernameOrEmail')
|
username_or_email: str = Field(..., alias='usernameOrEmail')
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
class Config:
|
|
||||||
populate_by_name = True
|
|
||||||
|
|
||||||
class AuthResponse(BaseModel):
|
class AuthResponse(BaseModel):
|
||||||
user: UserResponse
|
user: UserResponse
|
||||||
token: str
|
token: str
|
||||||
|
|
||||||
class TaskListResponse(BaseModel):
|
class TaskListResponse(BaseModel):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
user_id: str
|
user_id: str
|
||||||
name: str
|
name: str
|
||||||
@ -78,9 +78,6 @@ class TaskListResponse(BaseModel):
|
|||||||
color: str = "#667eea"
|
color: str = "#667eea"
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
class Config:
|
|
||||||
from_attributes = True
|
|
||||||
|
|
||||||
class TaskListCreate(BaseModel):
|
class TaskListCreate(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
icon: Optional[str] = "📝"
|
icon: Optional[str] = "📝"
|
||||||
@ -92,6 +89,8 @@ class TaskListUpdate(BaseModel):
|
|||||||
color: Optional[str] = None
|
color: Optional[str] = None
|
||||||
|
|
||||||
class TaskResponse(BaseModel):
|
class TaskResponse(BaseModel):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
list_id: str
|
list_id: str
|
||||||
user_id: str
|
user_id: str
|
||||||
@ -102,9 +101,6 @@ class TaskResponse(BaseModel):
|
|||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
|
||||||
from_attributes = True
|
|
||||||
|
|
||||||
class TaskCreate(BaseModel):
|
class TaskCreate(BaseModel):
|
||||||
title: str
|
title: str
|
||||||
list_id: str
|
list_id: str
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user