hngprojects / hng_boilerplate_python_fastapi_web

Apache License 2.0
153 stars 138 forks source link

[FEAT] Implement User Profile Settings Update API Endpoint #86

Open Ukeme-Edet opened 1 month ago

Ukeme-Edet commented 1 month ago

Description

Implement a RESTful API endpoint to handle partial updates of user profile settings. This endpoint will allow authenticated users to modify specific parts of their profile information, such as name, email, or preferences. User preferences will be stored as a JSON field in the user table of the database.

Acceptance Criteria

API Endpoint Implementation:

Data Validation and Authorization:

Updating User Profile:

Response:

Request Example:

PATCH /api/users/profile

{
  "name": "John Doe",
  "email": "john.doe@example.com",
  "preferences": {
    "newsletter": true,
    "darkMode": false
  }
}

Successful Response:

{
  "message": "Profile updated successfully",
  "user": {
    "name": "John Doe",
    "email": "existing.email@example.com",
    "preferences": {
      "newsletter": true,
      "darkMode": false
    }
  },
  "status": 200
}

Error response:

Purpose

Provide a secure and efficient backend service for users to update specific parts of their profile settings, ensuring data validation and maintaining user information integrity.

Requirements

Database Schema

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    name VARCHAR(100),
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    preferences JSONB DEFAULT '{}'::jsonb
);

CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_username ON users(username);

image

Expected Outcome

A fully functional API endpoint that securely handles partial user profile updates, maintaining data integrity and providing clear feedback on the success or failure of update attempts.

Status Codes:

Testing

Ukeme-Edet commented 1 month ago

The link to the approved issue is here

Ukeme-Edet commented 1 month ago

@prondubuisi @bolexs @zxenonx could you assign me to the ticket 👀

theijhay commented 1 month ago

@Ukeme-Edet your version of api v1

Ukeme-Edet commented 1 month ago

Sorry, I don't get you @theijhay

theijhay commented 1 month ago

PATCH /api/v1/users/profile instead PATCH /api/users/profile But PATCH? Not GET?

Ukeme-Edet commented 1 month ago

@theijhay The endpoint used was instructed by a mentor here and yeah it's PATCH since it's an update :)

Ukeme-Edet commented 1 month ago

@theijhay Please could you assign the ticket to me and add the approved tag