Refactor/issue 29 add pydantic validations #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors data validation in all user-related DTO (Data Transfer Object) classes by replacing custom Pydantic validators with built-in Pydantic
Fieldconstraints andAnnotatedtypes. The changes ensure that string fields are non-empty and whitespace-trimmed, and numeric fields are within valid ranges, using declarative schema definitions instead of imperative validation methods. This approach improves code readability, maintainability, and leverages Pydantic's built-in validation mechanisms.Key changes by theme:
Validation Refactoring:
@field_validatorand@validatormethods with PydanticFieldconstraints (such asmin_length=1,strip_whitespace=True, and numeric bounds likege=0,ge=1,le=12) and usedAnnotatedtypes for clarity in all DTO classes (user_entity.py,education_entity.py,certification_entity.py,projects_entity.py,links_entity.py,location_entity.py,publication_entity.py,profile_entity.py). [1] [2] [3] [4] [5] [6] [7] [8]Schema Improvements:
Codebase Simplification:
Consistency and Best Practices:
These changes modernize the DTO validation approach, making the codebase more robust and easier to extend.