You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **UserController ** handles the user CRUD endpoints requests. When a request is received, the flow follows these steps:
Receive Request:
The request typically includes user data such as name, email, and password. For user registration, a UserRegisterRequest DTO is used to encapsulate this information.
DTO Validation:
The UserRegisterRequest DTO is used for user registration requests. This DTO includes fields such as name, email, password, and phoneNumber. Validation annotations like @NotBlank, @Size, and custom validations ensure that:
The name field is not empty.
The email is properly formatted and not already in use.
The password has the required length (e.g., at least 8 characters).
The phoneNumber field is not empty.
These validations are handled by the ValidationService, ensuring that only valid user data proceeds to the next steps.
Validation Outcome:
If the user data passes all validations, the flow continues to the UserService to apply business logic.
If any validation fails (e.g., a missing field or an invalid email format), a ValidationErrorResponse DTO is returned, detailing the validation errors.
Business Logic and Custom Validations in UserService:
Once the DTO is valid, the UserService checks if the user already exists in the system by checking the email or phoneNumber. If a duplicate is found, a custom exception like IncorrectPasswordException or UserPermissionException is thrown.
The GlobalExceptionHandler catches the exception and returns an error response indicating that the user already exists.
Process User Data:
If no duplicate user is found, the user is created or updated in the system based on the provided data.
For new users, the system stores the user data, including the hashed password and any other relevant information.
Return Response:
After processing the user data, the system returns a success message or the newly created user data, depending on the request (e.g., a confirmation message for registration or updated user details).
GlobalExceptionHandler:
The GlobalExceptionHandler plays a key role in catching any exceptions, such as validation errors or custom exceptions (e.g., IncorrectPasswordException), and returning appropriate ValidationErrorResponse DTO with clear error messages.
📋documentationImprovements or additions to documentation⬅️BACKEND🧠 logicHandles business rules, data processing, and internal logic.
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
UserController Validation Flow:
The **UserController ** handles the user CRUD endpoints requests. When a request is received, the flow follows these steps:
Receive Request:
DTO Validation:
The UserRegisterRequest DTO is used for user registration requests. This DTO includes fields such as
name
,email
,password
, andphoneNumber
. Validation annotations like@NotBlank
,@Size
, and custom validations ensure that:The
name
field is not empty.The
email
is properly formatted and not already in use.The
password
has the required length (e.g., at least 8 characters).The
phoneNumber
field is not empty.These validations are handled by the ValidationService, ensuring that only valid user data proceeds to the next steps.
Validation Outcome:
If the user data passes all validations, the flow continues to the UserService to apply business logic.
If any validation fails (e.g., a missing field or an invalid email format), a ValidationErrorResponse DTO is returned, detailing the validation errors.
Business Logic and Custom Validations in UserService:
Once the DTO is valid, the UserService checks if the user already exists in the system by checking the
email
orphoneNumber
. If a duplicate is found, a custom exception likeIncorrectPasswordException
orUserPermissionException
is thrown.The GlobalExceptionHandler catches the exception and returns an error response indicating that the user already exists.
Process User Data:
If no duplicate user is found, the user is created or updated in the system based on the provided data.
For new users, the system stores the user data, including the hashed password and any other relevant information.
Return Response:
GlobalExceptionHandler:
IncorrectPasswordException
), and returning appropriate ValidationErrorResponse DTO with clear error messages.Beta Was this translation helpful? Give feedback.
All reactions