Refactor DTO classes to use model_config with ConfigDict for attribute handling
- Updated multiple DTO classes across various modules to replace the `Config` class with `model_config = ConfigDict(from_attributes=True)`. - This change enhances consistency in attribute handling and aligns with the latest Pydantic practices. - Adjusted error handling in core modules to change status codes from `HTTP_422_UNPROCESSABLE_ENTITY` to `HTTP_422_UNPROCESSABLE_CONTENT` for improved clarity in validation responses.
This commit is contained in:
@@ -6,7 +6,7 @@ Reemplaza schemas.py siguiendo enfoque DDD y estilo NestJS
|
||||
from decimal import Decimal
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
from .validators import is_valid_rfc, is_valid_tax_id
|
||||
|
||||
@@ -36,8 +36,7 @@ class ClientProviderAddressDTO(BaseModel):
|
||||
contact: Optional[str] = Field(None, max_length=50, description="Contact person")
|
||||
reference: Optional[str] = Field(None, max_length=250, description="Reference")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# DTOs para programas
|
||||
@@ -86,8 +85,7 @@ class ClientProviderProgramsDTO(BaseModel):
|
||||
None, max_length=300, description="AUTSE number"
|
||||
)
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# DTOs principales
|
||||
@@ -145,8 +143,7 @@ class ClientProviderCreateDTO(BaseModel):
|
||||
)
|
||||
return self
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ClientProviderUpdateDTO(BaseModel):
|
||||
@@ -203,8 +200,7 @@ class ClientProviderUpdateDTO(BaseModel):
|
||||
)
|
||||
return self
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ClientProviderResponseDTO(BaseModel):
|
||||
@@ -232,8 +228,7 @@ class ClientProviderResponseDTO(BaseModel):
|
||||
address: Optional[ClientProviderAddressDTO] = None
|
||||
programs: Optional[ClientProviderProgramsDTO] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# DTOs para respuestas específicas
|
||||
@@ -247,8 +242,7 @@ class ClientProviderBasicDTO(BaseModel):
|
||||
client_or_provider: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ClientProviderListDTO(BaseModel):
|
||||
@@ -259,8 +253,7 @@ class ClientProviderListDTO(BaseModel):
|
||||
page: int
|
||||
size: int
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ClientProviderPaginatedResponseDTO(BaseModel):
|
||||
@@ -271,5 +264,4 @@ class ClientProviderPaginatedResponseDTO(BaseModel):
|
||||
page: int
|
||||
page_size: int
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
Reference in New Issue
Block a user