Skip to content

TO-291: Add notification API endpoints#640

Open
almeidaraul wants to merge 5 commits intoTO-291/add-notifications-tablefrom
TO-291/add-api-endpoints
Open

TO-291: Add notification API endpoints#640
almeidaraul wants to merge 5 commits intoTO-291/add-notifications-tablefrom
TO-291/add-api-endpoints

Conversation

@almeidaraul
Copy link
Contributor

Description

Added API functionality related to notifications

Resolved issues

Part of TO-291

Web service API changes

Added new endpoints for editing notifications

@almeidaraul almeidaraul changed the title Add notification API endpoints TO-291: Add notification API endpoints Mar 11, 2026
@almeidaraul almeidaraul requested a review from Copilot March 13, 2026 16:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}/read endpoints.
  • 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants