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.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import RedirectResponse
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import Session
|
||||
@ -46,31 +46,31 @@ app.add_middleware(
|
||||
|
||||
# Pydantic Models for API
|
||||
class UserResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: str
|
||||
username: str
|
||||
email: str
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class UserRegister(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
password: str
|
||||
|
||||
class UserLogin(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
username_or_email: str = Field(..., alias='usernameOrEmail')
|
||||
password: str
|
||||
|
||||
class Config:
|
||||
populate_by_name = True
|
||||
|
||||
class AuthResponse(BaseModel):
|
||||
user: UserResponse
|
||||
token: str
|
||||
|
||||
class TaskListResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: str
|
||||
user_id: str
|
||||
name: str
|
||||
@ -78,9 +78,6 @@ class TaskListResponse(BaseModel):
|
||||
color: str = "#667eea"
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class TaskListCreate(BaseModel):
|
||||
name: str
|
||||
icon: Optional[str] = "📝"
|
||||
@ -92,6 +89,8 @@ class TaskListUpdate(BaseModel):
|
||||
color: Optional[str] = None
|
||||
|
||||
class TaskResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: str
|
||||
list_id: str
|
||||
user_id: str
|
||||
@ -102,9 +101,6 @@ class TaskResponse(BaseModel):
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class TaskCreate(BaseModel):
|
||||
title: str
|
||||
list_id: str
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user