schemas_v1_db_queries_notification - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/schemas/v1/db/queries/notification.rs
- async fn list_user_notifications
- async fn count_unread_user_notifications
- async fn get_user_notification_by_id
- async fn create_user_notification
- async fn mark_user_notification_as_read
- async fn mark_all_user_notifications_as_read
- async fn delete_user_notification
- async fn delete_read_user_notifications
- async fn list_role_notifications
- async fn create_role_notification
- async fn get_role_notification_by_id
- async fn delete_role_notification
- async fn create_notification_acknowledgment
- async fn has_acknowledged_role_notification
- async fn get_user_role_notifications
- async fn get_all_user_notifications_with_count
pub async fn list_user_notifications(
pool: &Pool<MySql>,
user_id: i64,
page: i64,
per_page: i64,
include_read: bool,
) -> anyhow::Result<Vec<UserNotification>> {
// ... function body
}
Retrieves a paginated list of notifications for a specific user. This function fetches a subset of notifications for a given user based on pagination parameters, ordering them by creation date in descending order (newest first). This helps manage large notification lists by retrieving only a specific "page" of results.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user whose notifications to retrieve -
page
- Zero-based page number (e.g., 0 for first page, 1 for second page) -
per_page
- Number of records to fetch per page -
include_read
- Whether to include notifications that have been marked as read
-
Ok(Vec<UserNotification>)
- Successfully retrieved list of notifications -
Err(anyhow::Error)
- Failed to fetch notifications, with context
pub async fn count_unread_user_notifications(
pool: &Pool<MySql>,
user_id: i64,
) -> anyhow::Result<i64> {
// ... function body
}
Counts unread notifications for a user. This function retrieves the count of unread notifications for a specific user, which is useful for displaying notification badges or alerts.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user whose unread notifications to count
-
Ok(i64)
- Successfully retrieved count of unread notifications -
Err(anyhow::Error)
- Failed to count notifications
pub async fn get_user_notification_by_id(
pool: &Pool<MySql>,
id: i64,
) -> anyhow::Result<UserNotification> {
// ... function body
}
Retrieves a specific user notification by its unique identifier. This function fetches a single user notification record matching the provided ID. It's typically used for retrieving detailed information about a specific notification.
-
pool
- Database connection pool for executing the query -
id
- Unique identifier of the notification to retrieve
-
Ok(UserNotification)
- Successfully retrieved notification -
Err(anyhow::Error)
- Failed to fetch notification (including if not found)
pub async fn create_user_notification(
pool: &Pool<MySql>,
user_id: i64,
message: &str,
notification_type: &str,
org_id: Option<i64>,
app_id: Option<i64>,
importance: Option<&str>,
action_url: Option<&str>,
action_label: Option<&str>,
expires_at: Option<chrono::DateTime<chrono::Utc>>,
) -> anyhow::Result<UserNotification> {
// ... function body
}
Creates a new notification for a user. This function inserts a new user notification record with the provided parameters. It handles both required fields and optional fields.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user to notify -
message
- The notification message text -
notification_type
- Type of notification (info, warning, error, success) -
org_id
- Optional organization ID related to the notification -
app_id
- Optional application ID related to the notification -
importance
- Optional importance level (default is "normal") -
action_url
- Optional URL for a related action -
action_label
- Optional label for the action button -
expires_at
- Optional expiration date for the notification
-
Ok(UserNotification)
- Successfully created notification, including database-assigned fields -
Err(anyhow::Error)
- Failed to create notification
pub async fn mark_user_notification_as_read(
pool: &Pool<MySql>,
id: i64,
) -> anyhow::Result<UserNotification> {
// ... function body
}
Marks a user notification as read. This function updates the read_status of a user notification to indicate that the user has viewed or acknowledged it.
-
pool
- Database connection pool for executing the query -
id
- Unique identifier of the notification to mark as read
-
Ok(UserNotification)
- Successfully updated notification -
Err(anyhow::Error)
- Failed to update notification
pub async fn mark_all_user_notifications_as_read(
pool: &Pool<MySql>,
user_id: i64,
) -> anyhow::Result<()> {
// ... function body
}
Marks all notifications for a user as read. This function updates the read_status of all notifications for a specific user to indicate that the user has viewed or acknowledged them.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user whose notifications to mark as read
-
Ok(())
- Successfully updated notifications -
Err(anyhow::Error)
- Failed to update notifications
pub async fn delete_user_notification(pool: &Pool<MySql>, id: i64) -> anyhow::Result<()> {
let mut tx = pool.begin().await?;
Deletes a user notification. This function permanently removes a user notification record with the specified ID. The operation is performed within a transaction to ensure data consistency.
-
pool
- Database connection pool for executing the query -
id
- Unique identifier of the notification to delete
-
Ok(())
- Successfully deleted the notification -
Err(anyhow::Error)
- Failed to delete the notification
pub async fn delete_read_user_notifications(
pool: &Pool<MySql>,
user_id: i64,
) -> anyhow::Result<i64> {
// ... function body
}
Deletes all read notifications for a user. This function permanently removes all notifications that have been marked as read for a specific user. This can be used as a "clear all" feature to help users maintain a clean notification list.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user whose read notifications should be deleted
-
Ok(i64)
- Number of notifications deleted -
Err(anyhow::Error)
- Failed to delete notifications
pub async fn list_role_notifications(
pool: &Pool<MySql>,
role_id: i64,
page: i64,
per_page: i64,
) -> anyhow::Result<Vec<RoleNotification>> {
// ... function body
}
Retrieves a paginated list of role notifications. This function fetches a subset of role notifications based on pagination parameters, ordering them by creation date in descending order (newest first).
-
pool
- Database connection pool for executing the query -
role_id
- ID of the role whose notifications to retrieve -
page
- Zero-based page number -
per_page
- Number of records to fetch per page
-
Ok(Vec<RoleNotification>)
- Successfully retrieved list of notifications -
Err(anyhow::Error)
- Failed to fetch notifications
pub async fn create_role_notification(
pool: &Pool<MySql>,
role_id: i64,
message: &str,
notification_type: &str,
org_id: Option<i64>,
app_id: Option<i64>,
importance: Option<&str>,
action_url: Option<&str>,
action_label: Option<&str>,
expires_at: Option<chrono::DateTime<chrono::Utc>>,
) -> anyhow::Result<RoleNotification> {
// ... function body
}
Creates a new notification for a role. This function inserts a new role notification record that will be visible to all users with the specified role.
-
pool
- Database connection pool for executing the query -
role_id
- ID of the role to notify -
message
- The notification message text -
notification_type
- Type of notification (info, warning, error, success) -
org_id
- Optional organization ID related to the notification -
app_id
- Optional application ID related to the notification -
importance
- Optional importance level (default is "normal") -
action_url
- Optional URL for a related action -
action_label
- Optional label for the action button -
expires_at
- Optional expiration date for the notification
-
Ok(RoleNotification)
- Successfully created notification -
Err(anyhow::Error)
- Failed to create notification
pub async fn get_role_notification_by_id(
pool: &Pool<MySql>,
id: i64,
) -> anyhow::Result<RoleNotification> {
// ... function body
}
Retrieves a specific role notification by its unique identifier.
-
pool
- Database connection pool for executing the query -
id
- Unique identifier of the role notification to retrieve
-
Ok(RoleNotification)
- Successfully retrieved notification -
Err(anyhow::Error)
- Failed to fetch notification
pub async fn delete_role_notification(pool: &Pool<MySql>, id: i64) -> anyhow::Result<()> {
let mut tx = pool.begin().await?;
Deletes a role notification. This function permanently removes a role notification record with the specified ID.
-
pool
- Database connection pool for executing the query -
id
- Unique identifier of the notification to delete
-
Ok(())
- Successfully deleted the notification -
Err(anyhow::Error)
- Failed to delete the notification
pub async fn create_notification_acknowledgment(
pool: &Pool<MySql>,
user_id: i64,
notification_id: Option<i64>,
role_notification_id: Option<i64>,
) -> anyhow::Result<NotificationAcknowledgment> {
// ... function body
}
Creates a notification acknowledgment for a user. This function records that a user has acknowledged a notification, which is useful for role-based notifications that need individual tracking.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user acknowledging the notification -
notification_id
- Optional ID of a user notification being acknowledged -
role_notification_id
- Optional ID of a role notification being acknowledged
-
Ok(NotificationAcknowledgment)
- Successfully created acknowledgment -
Err(anyhow::Error)
- Failed to create acknowledgment
pub async fn has_acknowledged_role_notification(
pool: &Pool<MySql>,
user_id: i64,
role_notification_id: i64,
) -> anyhow::Result<bool> {
// ... function body
}
Checks if a user has acknowledged a specific role notification.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user to check -
role_notification_id
- ID of the role notification to check
-
Ok(bool)
- True if acknowledged, false otherwise -
Err(anyhow::Error)
- Failed to check acknowledgment status
pub async fn get_user_role_notifications(
pool: &Pool<MySql>,
user_id: i64,
page: i64,
per_page: i64,
) -> anyhow::Result<Vec<UserNotificationWithRoleNotifications>> {
// ... function body
}
Retrieves all role notifications for a user with acknowledgment status. This function fetches role notifications for all roles a user has, along with information about whether the user has acknowledged each notification.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user -
page
- Zero-based page number -
per_page
- Number of records to fetch per page
-
Ok(Vec<RoleNotificationWithAcknowledgment>)
- Successfully retrieved notifications with acknowledgment status -
Err(anyhow::Error)
- Failed to fetch notifications
pub async fn get_all_user_notifications_with_count(
pool: &Pool<MySql>,
user_id: i64,
page: i64,
per_page: i64,
) -> anyhow::Result<NotificationWithCount> {
// ... function body
}
Gets notifications for a user from all sources with unread count. This function provides a comprehensive view of all notifications relevant to a user, including both direct user notifications and role-based notifications applicable to the user's roles. It also includes a count of unread notifications.
-
pool
- Database connection pool for executing the query -
user_id
- ID of the user -
page
- Zero-based page number -
per_page
- Number of records to fetch per page
-
Ok(NotificationWithCount)
- Successfully retrieved notifications with count -
Err(anyhow::Error)
- Failed to fetch notifications