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)
|
||||
|
||||
@@ -6,7 +6,7 @@ Reemplaza schemas.py siguiendo enfoque DDD y estilo NestJS
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CompanyCreateDTO(BaseModel):
|
||||
@@ -221,8 +221,7 @@ class CompanyCreateDTO(BaseModel):
|
||||
cancel_key_exp: Optional[int] = None
|
||||
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class CompanyUpdateDTO(CompanyCreateDTO):
|
||||
@@ -417,5 +416,4 @@ class CompanyResponseDTO(BaseModel):
|
||||
|
||||
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -19,8 +19,7 @@ class TariffFractionCreateDTO(BaseModel):
|
||||
adv_impo: Optional[str] = Field(None, max_length=20, description="Ad valorem importación")
|
||||
adv_expo: Optional[str] = Field(None, max_length=20, description="Ad valorem exportación")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TariffFractionUpdateDTO(BaseModel):
|
||||
@@ -33,8 +32,7 @@ class TariffFractionUpdateDTO(BaseModel):
|
||||
adv_impo: Optional[str] = Field(None, max_length=20, description="Ad valorem importación")
|
||||
adv_expo: Optional[str] = Field(None, max_length=20, description="Ad valorem exportación")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TariffFractionResponseDTO(BaseModel):
|
||||
@@ -66,8 +64,7 @@ class TariffFractionBasicDTO(BaseModel):
|
||||
adv_impo: Optional[str] = None
|
||||
adv_expo: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TariffFractionListDTO(BaseModel):
|
||||
@@ -79,8 +76,7 @@ class TariffFractionListDTO(BaseModel):
|
||||
page_size: int
|
||||
pages: int
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TariffFractionSearchDTO(BaseModel):
|
||||
@@ -92,5 +88,4 @@ class TariffFractionSearchDTO(BaseModel):
|
||||
nico: Optional[str] = Field(None, description="Filtrar por NICO")
|
||||
umt: Optional[str] = Field(None, description="Filtrar por UMT")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
Reference in New Issue
Block a user