Develop API endpoints that allow users to toggle between light and dark modes for the application. The user’s theme preference should be stored and retrieved from the existing users table.
Acceptance Criteria
The endpoint /api/v1/user/theme is accessible via POST and GET requests.
When a valid theme preference (light or dark) is provided, the endpoint updates the user's theme preference and returns a 200 OK status.
When an invalid theme preference is provided, the endpoint returns a 400 Bad Request status.
The endpoint should return the current theme preference for the user when accessed via a GET request.
Ensure that all unit and integration tests for the theme switcher feature are comprehensive, accurate, and verify the functionality correctly.
Purpose
To provide users with the ability to switch between light and dark themes, enhancing user experience and accessibility.
Requirements
Implement an endpoint to update and retrieve theme preferences.
Store the theme preference in the existing users table.
Handle situations where an invalid theme preference is provided.
Ensure secure and efficient storage and retrieval of user preferences.
Expected Outcome
API endpoints that allow users to toggle between light and dark modes and store their preferences securely in the existing users table.
Tasks
Add a theme column to the existing users table.
Create an endpoint /api/v1/user/theme to update and retrieve user theme preferences.
Implement server-side logic to handle theme preference updates and retrieval requests.
Ensure all sensitive data is encrypted and secure.
Implement logging for errors and theme preference update attempts.
Write unit tests for the theme switcher endpoint.
Write integration tests for the theme switcher logic.
Perform security testing to ensure data protection and compliance.
Endpoint URL
[POST] /api/v1/user/theme
Request Body:
{
"user_id": "string",
"theme": "string" // "light" or "dark"
}
Description
Develop API endpoints that allow users to toggle between light and dark modes for the application. The user’s theme preference should be stored and retrieved from the existing
users
table.Acceptance Criteria
/api/v1/user/theme
is accessible via POST and GET requests.light
ordark
) is provided, the endpoint updates the user's theme preference and returns a 200 OK status.Purpose
To provide users with the ability to switch between light and dark themes, enhancing user experience and accessibility.
Requirements
users
table.Expected Outcome
API endpoints that allow users to toggle between light and dark modes and store their preferences securely in the existing
users
table.Tasks
theme
column to the existingusers
table./api/v1/user/theme
to update and retrieve user theme preferences.Endpoint URL
[POST] /api/v1/user/theme
Request Body:
Successful Response:
Error Response:
[GET] /api/v1/user/theme
Successful Response:
Error Response:
Example Request
Fetch Theme Preference:
Update Theme Preference:
Testing
Test Scenarios
Successful Toggle
State Persistence
Invalid Theme Preference
invalid_theme
).Unexpected Error Handling
Fetching Theme Preference