TO-291: Add notification API endpoints#640
Open
almeidaraul wants to merge 5 commits intoTO-291/add-notifications-tablefrom
Open
TO-291: Add notification API endpoints#640almeidaraul wants to merge 5 commits intoTO-291/add-notifications-tablefrom
almeidaraul wants to merge 5 commits intoTO-291/add-notifications-tablefrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-pass notifications API endpoints to the backend so clients can list notifications, fetch unread counts, and mark notifications as read.
Changes:
- Introduces
/v1/notifications,/v1/notifications/unread-count, and/v1/notifications/{notification_id}/readendpoints. - Adds controller tests and a test data generator helper for notifications.
- Updates the generated OpenAPI schema and registers the new router.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/tests/data_generator.py | Adds gen_notification() to generate Notification records for tests. |
| backend/tests/controllers/notifications/test_notifications.py | Adds test coverage for listing, unread count, and marking notifications as read. |
| backend/test_observer/controllers/router.py | Registers the notifications router under /v1/notifications. |
| backend/test_observer/controllers/notifications/notifications.py | Implements notification listing, unread-count, and mark-as-read endpoints. |
| backend/test_observer/controllers/notifications/init.py | Exposes the notifications router. |
| backend/schemata/openapi.json | Updates OpenAPI paths/schemas for the new notification endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+79
to
+85
| notification = db.get(Notification, notification_id) | ||
| if not notification: | ||
| raise HTTPException(status_code=404, detail="Notification not found") | ||
|
|
||
| if notification.user_id != user.id: | ||
| raise HTTPException(status_code=403, detail="Not authorized to modify this notification") | ||
|
|
Comment on lines
+86
to
+88
| notification.dismissed_at = datetime.now() | ||
| db.commit() | ||
| db.refresh(notification) |
Comment on lines
+29
to
+41
| def _create_session_cookie(session_id: int) -> str: | ||
| """Create a signed session cookie for testing""" | ||
| signer = itsdangerous.TimestampSigner(str(SESSIONS_SECRET)) | ||
| session_data = {"id": session_id} | ||
| session_json = json.dumps(session_data) | ||
| return signer.sign(b64encode(session_json.encode()).decode()).decode() | ||
|
|
||
|
|
||
| def _authenticate_user(test_client: TestClient, user: User, generator: DataGenerator): | ||
| """Helper to authenticate a user in test client""" | ||
| session = generator.gen_user_session(user) | ||
| session_cookie = _create_session_cookie(session.id) | ||
| test_client.cookies.set("session", session_cookie) |
Comment on lines
+33
to
+48
| @router.get("", response_model=NotificationsResponse) | ||
| def get_notifications( | ||
| user: User | None = Depends(get_current_user), | ||
| db: Session = Depends(get_db), | ||
| ): | ||
| """Get all notifications for the logged in user""" | ||
| if not user: | ||
| raise HTTPException(status_code=401, detail="Not authenticated") | ||
|
|
||
| notifications = db.scalars( | ||
| select(Notification) | ||
| .where(Notification.user_id == user.id) | ||
| .order_by(Notification.created_at.desc()) | ||
| ).all() | ||
|
|
||
| return NotificationsResponse(notifications=list(notifications)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added API functionality related to notifications
Resolved issues
Part of TO-291
Web service API changes
Added new endpoints for editing notifications