|
16 | 16 | * **Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
|
17 | 17 | * **Request Traceability:** Generates a unique `requestId` (UUID v4) for each incoming request, included in success response metadata and available for server-side logging via context.
|
18 | 18 | * **In-Memory Demo Mode:** Utilizes pre-loaded fixture data (`lib/src/fixtures/`) for demonstration and development purposes, simulating a live backend without external dependencies for core data, settings, and email sending.
|
19 |
| -* **Authentication:** Provides endpoints for user sign-in/sign-up via email code and anonymous sign-in. Includes token generation and validation via middleware. |
| 19 | + * **Authentication:** Provides endpoints for user sign-in/sign-up via email code and anonymous sign-in. Includes token generation and validation. All Data and User Settings API endpoints now require authentication. |
20 | 20 |
|
21 | 21 | ### Data API (`/api/v1/data`)
|
22 | 22 |
|
| 23 | +* **Authentication Required:** All operations on this endpoint require a valid authentication token. |
23 | 24 | * **Generic Data Endpoint:** Provides a unified RESTful interface for performing CRUD (Create, Read, Update, Delete) operations on multiple data models.
|
24 | 25 | * **Model Agnostic Design:** Supports various data types through a single endpoint structure, determined by the `?model=` query parameter.
|
25 |
| -* **Currently Supported Data Models:** |
| 26 | +* **Data Scoping:** Can serve global data (e.g., news articles, accessible to any authenticated user) or user-specific data (for future models, accessible only to the authenticated owner), based on the model's server-side configuration (`ModelConfig.ownership`). |
| 27 | +* **Currently Supported Data Models (as global):** |
26 | 28 | * `headline`
|
27 | 29 | * `category`
|
28 | 30 | * `source`
|
29 | 31 | * `country`
|
30 | 32 |
|
31 |
| -### User Settings API (`/api/v1/users/me/settings`) |
| 33 | +### User Settings API (`/api/v1/users/{userId}/settings`) |
32 | 34 |
|
33 |
| -* **User-Specific Settings Management:** Provides RESTful endpoints for managing application settings (currently treated globally, future enhancement for user-specific). |
| 35 | +* **User-Specific Settings Management:** Provides RESTful endpoints for an authenticated user to manage their own application settings. The `{userId}` in the path must match the ID of the authenticated user. |
| 36 | +* **Authentication Required:** All operations require a valid authentication token. |
34 | 37 | * **Supported Settings:**
|
35 | 38 | * Display Settings (Theme, Font, etc.)
|
36 | 39 | * Language Preference
|
@@ -139,9 +142,11 @@ These endpoints handle user authentication flows.
|
139 | 142 |
|
140 | 143 | ## API Endpoints: Data (`/api/v1/data`)
|
141 | 144 |
|
| 145 | +**Authentication required for all operations.** |
| 146 | + |
142 | 147 | This endpoint serves as the single entry point for accessing different data models. The specific model is determined by the `model` query parameter.
|
143 | 148 |
|
144 |
| -**Supported `model` values:** `headline`, `category`, `source`, `country` |
| 149 | +**Supported `model` values (currently global):** `headline`, `category`, `source`, `country` |
145 | 150 |
|
146 | 151 | **Standard Response Structure:** (Applies to both Data and Settings APIs)
|
147 | 152 |
|
@@ -179,69 +184,79 @@ This endpoint serves as the single entry point for accessing different data mode
|
179 | 184 | * **Path:** `/api/v1/data?model=<model_name>`
|
180 | 185 | * **Request Body:** JSON object representing the item to create (using `camelCase` keys).
|
181 | 186 | * **Success Response:** `201 Created` with `SuccessApiResponse<T>` containing the created item.
|
182 |
| - * **Example:** `POST /api/v1/data?model=category` with body `{"name": "Sports", "description": "News about sports"}` |
| 187 | + * **Example:** `POST /api/v1/data?model=category` with body `{"name": "Sports", "description": "News about sports"}` (Requires Bearer token) |
183 | 188 |
|
184 | 189 | 3. **Get Item by ID**
|
185 | 190 | * **Method:** `GET`
|
186 | 191 | * **Path:** `/api/v1/data/<item_id>?model=<model_name>`
|
| 192 | + * **Authentication:** Required (Bearer Token). |
187 | 193 | * **Success Response:** `200 OK` with `SuccessApiResponse<T>`.
|
188 |
| - * **Error Response:** `404 Not Found`. |
189 |
| - * **Example:** `GET /api/v1/data/some-headline-id?model=headline` |
| 194 | + * **Error Response:** `401 Unauthorized`, `404 Not Found`. |
| 195 | + * **Example:** `GET /api/v1/data/some-headline-id?model=headline` (Requires Bearer token) |
190 | 196 |
|
191 | 197 | 4. **Update Item by ID**
|
192 | 198 | * **Method:** `PUT`
|
193 | 199 | * **Path:** `/api/v1/data/<item_id>?model=<model_name>`
|
| 200 | + * **Authentication:** Required (Bearer Token). |
194 | 201 | * **Request Body:** JSON object representing the complete updated item (must include `id`, using `camelCase` keys).
|
195 | 202 | * **Success Response:** `200 OK` with `SuccessApiResponse<T>`.
|
196 |
| - * **Error Response:** `404 Not Found`, `400 Bad Request`. |
197 |
| - * **Example:** `PUT /api/v1/data/some-category-id?model=category` with updated category JSON (e.g., `{"id": "...", "name": "...", "description": "..."}`). |
| 203 | + * **Error Response:** `401 Unauthorized`, `404 Not Found`, `400 Bad Request`. |
| 204 | + * **Example:** `PUT /api/v1/data/some-category-id?model=category` with updated category JSON (Requires Bearer token). |
198 | 205 |
|
199 | 206 | 5. **Delete Item by ID**
|
200 | 207 | * **Method:** `DELETE`
|
201 | 208 | * **Path:** `/api/v1/data/<item_id>?model=<model_name>`
|
| 209 | + * **Authentication:** Required (Bearer Token). |
202 | 210 | * **Success Response:** `204 No Content`.
|
203 |
| - * **Error Response:** `404 Not Found`. |
204 |
| - * **Example:** `DELETE /api/v1/data/some-source-id?model=source` |
| 211 | + * **Error Response:** `401 Unauthorized`, `404 Not Found`. |
| 212 | + * **Example:** `DELETE /api/v1/data/some-source-id?model=source` (Requires Bearer token) |
| 213 | + |
| 214 | +## API Endpoints: User Settings (`/api/v1/users/{userId}/settings`) |
205 | 215 |
|
206 |
| -## API Endpoints: User Settings (`/api/v1/users/me/settings`) |
| 216 | +These endpoints manage application settings for an authenticated user. The `{userId}` in the path must match the ID of the authenticated user. |
207 | 217 |
|
208 |
| -These endpoints manage application settings. Currently, they operate on a global set of settings due to the lack of authentication; future enhancements will make them user-specific. |
| 218 | +**Authentication Required for all operations.** |
209 | 219 |
|
210 | 220 | **Standard Response Structure:** Uses the same `SuccessApiResponse` and error structure as the Data API.
|
211 | 221 |
|
212 | 222 | **Settings Operations:**
|
213 | 223 |
|
214 | 224 | 1. **Get Display Settings**
|
215 | 225 | * **Method:** `GET`
|
216 |
| - * **Path:** `/api/v1/users/me/settings/display` |
| 226 | + * **Path:** `/api/v1/users/{userId}/settings/display` |
217 | 227 | * **Success Response:** `200 OK` with `SuccessApiResponse<DisplaySettings>`.
|
218 |
| - * **Example:** `GET /api/v1/users/me/settings/display` |
| 228 | + * **Error Response:** `401 Unauthorized`, `403 Forbidden`. |
| 229 | + * **Example:** `GET /api/v1/users/user-abc-123/settings/display` (Requires Bearer token for user-abc-123) |
219 | 230 |
|
220 | 231 | 2. **Update Display Settings**
|
221 | 232 | * **Method:** `PUT`
|
222 |
| - * **Path:** `/api/v1/users/me/settings/display` |
| 233 | + * **Path:** `/api/v1/users/{userId}/settings/display` |
223 | 234 | * **Request Body:** JSON object representing the complete `DisplaySettings` (using `camelCase` keys).
|
224 | 235 | * **Success Response:** `200 OK` with `SuccessApiResponse<DisplaySettings>` containing the updated settings.
|
225 |
| - * **Example:** `PUT /api/v1/users/me/settings/display` with body `{"baseTheme": "dark", "accentTheme": "newsRed", ...}`. |
| 236 | + * **Error Response:** `401 Unauthorized`, `403 Forbidden`, `400 Bad Request`. |
| 237 | + * **Example:** `PUT /api/v1/users/user-abc-123/settings/display` with body `{"baseTheme": "dark", ...}` (Requires Bearer token for user-abc-123). |
226 | 238 |
|
227 | 239 | 3. **Get Language Setting**
|
228 | 240 | * **Method:** `GET`
|
229 |
| - * **Path:** `/api/v1/users/me/settings/language` |
| 241 | + * **Path:** `/api/v1/users/{userId}/settings/language` |
230 | 242 | * **Success Response:** `200 OK` with `SuccessApiResponse<Map<String, String>>` (e.g., `{"data": {"language": "en"}, ...}`).
|
231 |
| - * **Example:** `GET /api/v1/users/me/settings/language` |
| 243 | + * **Error Response:** `401 Unauthorized`, `403 Forbidden`. |
| 244 | + * **Example:** `GET /api/v1/users/user-abc-123/settings/language` (Requires Bearer token for user-abc-123) |
232 | 245 |
|
233 | 246 | 4. **Update Language Setting**
|
234 | 247 | * **Method:** `PUT`
|
235 |
| - * **Path:** `/api/v1/users/me/settings/language` |
| 248 | + * **Path:** `/api/v1/users/{userId}/settings/language` |
236 | 249 | * **Request Body:** JSON object `{"language": "<code>"}` (e.g., `{"language": "es"}`).
|
237 | 250 | * **Success Response:** `200 OK` with `SuccessApiResponse<Map<String, String>>` containing the updated language setting.
|
238 |
| - * **Example:** `PUT /api/v1/users/me/settings/language` with body `{"language": "fr"}`. |
| 251 | + * **Error Response:** `401 Unauthorized`, `403 Forbidden`, `400 Bad Request`. |
| 252 | + * **Example:** `PUT /api/v1/users/user-abc-123/settings/language` with body `{"language": "fr"}` (Requires Bearer token for user-abc-123). |
239 | 253 |
|
240 | 254 | 5. **Clear All Settings**
|
241 | 255 | * **Method:** `DELETE`
|
242 |
| - * **Path:** `/api/v1/users/me/settings` |
| 256 | + * **Path:** `/api/v1/users/{userId}/settings` |
243 | 257 | * **Success Response:** `204 No Content`.
|
244 |
| - * **Example:** `DELETE /api/v1/users/me/settings` |
| 258 | + * **Error Response:** `401 Unauthorized`, `403 Forbidden`. |
| 259 | + * **Example:** `DELETE /api/v1/users/user-abc-123/settings` (Requires Bearer token for user-abc-123) |
245 | 260 |
|
246 | 261 | ## Setup & Running
|
247 | 262 |
|
|
0 commit comments