API Reference
Notifications module for user notification management.
This module handles the creation, retrieval, and management of user notifications including activity alerts, follower requests, and admin approval notifications.
Exports
- CRUD: get_user_notification_by_id, get_user_notifications, get_user_notifications_count, get_user_notifications_with_pagination, create_notification, mark_notification_as_read
- Schemas: NotificationBase, NotificationCreate, NotificationRead
- Models: Notification (ORM model)
- Constants: NotificationType
- Utils: create_new_activity_notification, create_new_duplicate_start_time_activity_notification, create_new_follower_request_notification, create_accepted_follower_request_notification, create_admin_new_sign_up_approval_request_notification
NotificationBase
Bases: BaseModel
Base schema for notification data.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
StrictInt | None
|
Type of the notification. |
options |
dict | None
|
Additional metadata for the notification. |
Source code in backend/app/notifications/schema.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
NotificationCreate
Bases: NotificationBase
Schema for creating a notification record.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
StrictInt
|
FK to user. |
Source code in backend/app/notifications/schema.py
40 41 42 43 44 45 46 47 48 49 50 51 52 | |
NotificationModel
Bases: Base
User notification data.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Mapped[int]
|
Primary key. |
user_id |
Mapped[int]
|
Foreign key to users table. |
type |
Mapped[int]
|
Notification type. |
options |
Mapped[dict[str, Any] | None]
|
Notification options (JSON). |
read |
Mapped[bool]
|
Whether the notification has been read. |
created_at |
Mapped[datetime]
|
Notification creation date. |
users |
Mapped[Users]
|
Relationship to Users model. |
Source code in backend/app/notifications/models.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
NotificationRead
Bases: NotificationBase
Schema for reading a notification record.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique notification identifier. |
user_id |
StrictInt
|
FK to user. |
read |
StrictBool
|
Whether the notification has been read. |
created_at |
datetime | None
|
Timestamp of creation. |
Source code in backend/app/notifications/schema.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
serialize_created_at
serialize_created_at(value)
Serialize created_at as date string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime | None
|
The datetime value to serialize. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Date string in YYYY-MM-DD format or None. |
Source code in backend/app/notifications/schema.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
NotificationType
Bases: IntEnum
Enumeration of notification types.
Attributes:
| Name | Type | Description |
|---|---|---|
NEW_ACTIVITY |
New activity notification. |
|
DUPLICATE_ACTIVITY |
Duplicate activity notification. |
|
NEW_FOLLOWER_REQUEST |
New follower request notification. |
|
NEW_FOLLOWER_REQUEST_ACCEPTED |
Follower request accepted notification. |
|
ADMIN_NEW_SIGN_UP_APPROVAL_REQUEST |
Admin sign-up approval request notification. |
Source code in backend/app/notifications/constants.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
create_accepted_follower_request_notification
async
create_accepted_follower_request_notification(user_id, target_user_id, websocket_manager, db)
Create an accepted follower request notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The accepting user ID. |
required |
target_user_id
|
int
|
The user to notify. |
required |
websocket_manager
|
WebSocketManager
|
WebSocket manager instance. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Notification
|
The created Notification model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If user not found or error. |
Source code in backend/app/notifications/utils.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
create_admin_new_sign_up_approval_request_notification
async
create_admin_new_sign_up_approval_request_notification(user, websocket_manager, db)
Notify all admins of a new sign-up request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Users
|
The user requesting sign-up. |
required |
websocket_manager
|
WebSocketManager
|
WebSocket manager instance. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If creation or notify fails. |
Source code in backend/app/notifications/utils.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
create_new_activity_notification
async
create_new_activity_notification(user_id, activity_id, websocket_manager)
Create a new activity notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The user ID to notify. |
required |
activity_id
|
int
|
The new activity ID. |
required |
websocket_manager
|
WebSocketManager
|
WebSocket manager instance. |
required |
Returns:
| Type | Description |
|---|---|
Notification
|
The created Notification model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If creation or notify fails. |
Source code in backend/app/notifications/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
create_new_duplicate_start_time_activity_notification
async
create_new_duplicate_start_time_activity_notification(user_id, activity_id, websocket_manager)
Create a duplicate start time notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The user ID to notify. |
required |
activity_id
|
int
|
The duplicate activity ID. |
required |
websocket_manager
|
WebSocketManager
|
WebSocket manager instance. |
required |
Returns:
| Type | Description |
|---|---|
Notification
|
The created Notification model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If creation or notify fails. |
Source code in backend/app/notifications/utils.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
create_new_follower_request_notification
async
create_new_follower_request_notification(user_id, target_user_id, websocket_manager, db)
Create a new follower request notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The requesting user ID. |
required |
target_user_id
|
int
|
The user to notify. |
required |
websocket_manager
|
WebSocketManager
|
WebSocket manager instance. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Notification
|
The created Notification model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If user not found or error. |
Source code in backend/app/notifications/utils.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
create_notification
create_notification(notification, db)
Create a new notification record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification
|
NotificationCreate
|
The notification data to create. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Notification
|
The newly created Notification model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_user_notification_by_id
get_user_notification_by_id(notification_id, user_id, db)
Retrieve a notification by ID for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
The notification ID. |
required |
user_id
|
int
|
The owning user ID. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Notification | None
|
Notification model if found, otherwise None. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
get_user_notifications
get_user_notifications(user_id, db)
Retrieve all notifications for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The owning user ID. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
list[Notification]
|
List of Notification models for the user. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
get_user_notifications_count
get_user_notifications_count(user_id, db)
Count notifications for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The owning user ID. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of notifications for the user. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
get_user_notifications_with_pagination
get_user_notifications_with_pagination(user_id, db, page_number=1, num_records=5)
Retrieve paginated notifications for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The owning user ID. |
required |
db
|
Session
|
Database session. |
required |
page_number
|
int
|
Page number (default 1). |
1
|
num_records
|
int
|
Records per page (default 5). |
5
|
Returns:
| Type | Description |
|---|---|
list[Notification]
|
List of Notification models for the page. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
mark_notification_as_read
mark_notification_as_read(notification_id, user_id, db)
Mark a notification as read for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_id
|
int
|
The notification ID. |
required |
user_id
|
int
|
The owning user ID. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
Notification | None
|
Updated Notification model, or None if not found. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If a database error occurs. |
Source code in backend/app/notifications/crud.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |