hngprojects / hng_boilerplate_php_laravel_web

Apache License 2.0
148 stars 58 forks source link

[FEAT] UPDATE USER PROFILE #224

Closed AdelakunShola closed 1 month ago

AdelakunShola commented 2 months ago

Description

Acceptance Criteria

Update User Profile Endpoint:

Endpoint: The endpoint /api/v1/profile/ should be accessible via a PATCH request.

Request Body: The request body should include the fields to be updated, such as:

Successful Update:

When a valid token and user ID are provided, the endpoint returns a 200 OK status with a success message and the updated profile details.

User Not Authenticated:

If the token is invalid or missing, the endpoint returns a 401 Unauthorized status with an appropriate error message.

User Not Found:

If the user ID does not exist, the endpoint returns a 404 Not Found status with an appropriate error message.

Server Error:

If an unexpected server error occurs, the endpoint returns a 500 Internal Server Error status with an appropriate error message.

Types of Changes Bug fix: Non-breaking change which fixes an issue. New feature: Non-breaking change which adds functionality. Breaking change: Fix or feature that would cause existing functionality to change.

Checklist:

  • [ ] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

Endpoints and Responses Update User Profile Endpoint Endpoint URL:

bash

PATCH /api/v1/profile/ Request Body:

json

{
  "pronouns": "Updated pronouns",
  "job_title": "Updated job title",
  "department": "Updated department",
  "social": "Updated social",
  "bio": "Updated bio",
  "phone_number": "+1234567890",
  "avatar_url": "updated_avatar_url",
  "recovery_email": "updated_recovery_email@example.com"
}

Responses:

Success Response:

Code: 200 OK Content:

json

{
  "message": "Profile updated successfully",
  "status_code": 200,
  "data": {
    "id": "user-id",
    "pronouns": "Updated pronouns",
    "job_title": "Updated job title",
    "department": "Updated department",
    "social": "Updated social",
    "bio": "Updated bio",
    "phone_number": "+1234567890",
    "avatar_url": "updated_avatar_url",
    "recovery_email": "updated_recovery_email@example.com",
    "updated_at": "DateTime"
  }

} Error Responses:

Code: 401 Unauthorized Content:

json

{
  "status_code": 401,
  "message": "User not authenticated"
}

Code: 404 Not Found Content:

json

{
  "status_code": 404,
  "message": "User not found"
}

Code: 500 Internal Server Error Content:

json

{
  "status_code": 500,
  "message": "An unexpected error occurred"
}

Purpose: The Update User Profile endpoint allows authenticated users to update their profile information. This ensures the profile update process is functioning correctly.

Requirements: Implement the Update User Profile endpoint to allow users to update their profile information. Handle authentication and authorization issues. Ensure proper input validation for the fields to be updated. Write unit tests and integration tests to cover the new functionality. Implement error handling for invalid inputs, non-existing users, and server errors. Ensure logging for error cases and successful updates. Expected Outcome: An endpoint that allows users to update their profile information, ensuring authentication, proper input validation, and robust error handling.

Tasks:

  • Define Update User Profile Endpoint:
  • Create an endpoint /api/v1/profile/ to update user profiles. Implement Logic:
  • Implement server-side logic to handle successful and failed profile update requests.
  • Input Validation:
  • Ensure input validation to verify the correctness of the fields to be updated. Database Query:
  • Write the necessary database queries to update user profiles. Error Handling:
  • Implement error handling for invalid inputs, non-existing users, and server errors.
  • Logging:
  • Implement logging for errors and successful profile updates.

Testing:

  • Write unit tests for the profile update functionality.
  • Write integration tests for the profile update logic.

Security:

  • Perform security testing to ensure data protection and compliance.
  • Ensure all sensitive data is encrypted and secure.
AdelakunShola commented 2 months ago

Slack id: Harry

This issue is linked to an already approved issue link