-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Add an endpoint to the Spring Boot REST API for user registration that will create both the User and the Profile records in a single request. This endpoint will ensure that the user and profile are created together in a transactional manner, ensuring atomicity and data consistency. The user registration process will also pre-validate if the email is already registered, generate a verification code, and send it to the user’s email.
Requirements:
-
User Registration Endpoint:
- Implement a
POSTAPI endpoint for user registration (e.g.,/api/auth/register). - The endpoint should accept the following fields in the request body:
email(String)password(String)fullName(String)profileData(Profile-related fields, e.g.,bio,profilePictureUrl, etc.)
- Implement a
-
Account Already Registered Check:
- Pre-validate that the email provided is not already registered by checking the existing users.
- If the email is already registered, return an appropriate error response (e.g.,
400 Bad Requestwith a message like "Email already in use").
-
User and Profile Creation:
- User Record: Create the user record in the database with the provided email and password. Store the password securely (using hashing).
- Profile Record: Create the associated profile record, including fields like
bio,profilePictureUrl, and any other relevant information. - Ensure both the user and profile records are created in the same transaction (atomic operation).
-
Verification Code Generation:
- Generate a verification code for the user and store it in the
Userentity along with an expiration date. - Send the verification code to the provided email using an email service.
- Generate a verification code for the user and store it in the
-
Response:
- If the user and profile are successfully created, return a success message with a
201 Createdstatus. - In case of errors (e.g., email already in use), return an appropriate error message with a proper HTTP status code (e.g.,
400 Bad Request).
- If the user and profile are successfully created, return a success message with a
-
User Model & Profile Model:
- Ensure the
Userentity has theisVerifiedflag to indicate if the user has verified their account. - The
Userentity should store theverificationCodeandexpirationDate(timestamp) to manage code expiration. - The
Profileentity should store profile-related data likebio,profilePictureUrl, etc.
- Ensure the
-
Security:
- Ensure the password is hashed and not stored in plain text.
- Ensure that the verification code is not exposed in the response or logs.
-
Testing:
- Write unit and integration tests for the user registration endpoint.
- Test for various scenarios (successful registration, email already in use, email sending failure, etc.).
Tasks:
- Implement the
POST /api/auth/registerendpoint to create both the user and profile records. - Pre-validate that the email is not already registered.
- Hash the password securely before saving it in the user record.
- Generate and send the verification code to the user's email.
- Handle error scenarios (e.g., email already in use, email sending failure).
- Write unit and integration tests for the user registration endpoint.
- Ensure security best practices are followed when creating the user and profile records.
- Add Swagger/OpenAPI documentation for the user registration endpoint.
Acceptance Criteria:
- A successful registration request results in the user and profile being created, the user being assigned a verification code, and an email being sent with the verification code.
- If the email is already in use, the response returns a
400 Bad Requeststatus with an appropriate message. - If the email fails to send, the response returns a
500 Internal Server Errorwith a message indicating the failure. - The user’s password is securely hashed.
- All relevant tests pass successfully.
Additional Notes:
- Follow the project’s existing conventions for exception handling, response formatting, and logging.
- Ensure that the user and profile records are created in a single transaction to maintain atomicity.
- Add relevant Swagger/OpenAPI documentation for the new user registration endpoint.
Metadata
Metadata
Assignees
Labels
featureNew featureNew feature
Type
Projects
Status
In progress