Skip to content

Conversation

@AmanDeol7
Copy link
Member

This pull request refactors data validation in all user-related DTO (Data Transfer Object) classes by replacing custom Pydantic validators with built-in Pydantic Field constraints and Annotated types. 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:

  • Replaced all custom @field_validator and @validator methods with Pydantic Field constraints (such as min_length=1, strip_whitespace=True, and numeric bounds like ge=0, ge=1, le=12) and used Annotated types 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:

  • Ensured all required string fields (such as names, usernames, IDs) are validated for non-empty values and whitespace is automatically stripped, both in creation and update DTOs. [1] [2] [3] [4] [5] [6] [7]
  • Added numeric bounds to relevant integer fields (e.g., months, GitHub stats, total lines contributed) to prevent invalid data entry. [1] [2]

Codebase Simplification:

Consistency and Best Practices:

  • Applied a consistent validation approach across all user-related entities, ensuring uniformity and reducing the risk of validation errors. (All references above)

These changes modernize the DTO validation approach, making the codebase more robust and easier to extend.

@AmanDeol7 AmanDeol7 changed the title Fix/issue 29 add pydantic validations Refactor/issue 29 add pydantic validations Oct 22, 2025
@JRS296 JRS296 added help wanted Extra attention is needed hacktoberfest Hacktoberfest related issues! labels Oct 23, 2025
@JRS296 JRS296 requested a review from happydracula October 23, 2025 10:52
Copy link
Member

@JRS296 JRS296 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmanDeol7 Moving to the new validation frame work is fine, but make sure there are not other breaking changes. From my knoweldge I approached it this way to have some synergy with the global test handlers. Kindly make sure everything works as expected

@happydracula
Copy link
Contributor

@AmanDeol7 Moving to the new validation frame work is fine, but make sure there are not other breaking changes. From my knoweldge I approached it this way to have some synergy with the global test handlers. Kindly make sure everything works as expected

Hey @AmanDeol7 if its possible can you share a few screenshots of maybe a couple APIs to show that everything is working fine? We can merge post that changes look good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest Hacktoberfest related issues! help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants