Skip to content

Notification API Documentation

Overview

This document explains the functionality of the NotificationViewSet and NotificationCategoryViewSet classes used to manage notifications in the API. These viewsets enable operations such as listing notifications, updating notification statuses, and managing notification categories. The base URL for these endpoints is api/v1/notification/.


Endpoints and Actions

NotificationCategoryViewSet

Endpoint HTTP Method Action Description Permissions
api/v1/notification/category/ GET list List all notification categories IsAuthenticated

NotificationViewSet

Endpoint HTTP Method Action Description Permissions
api/v1/notification/ GET list List all notifications for the authenticated user IsAuthenticated
api/v1/notification/ PATCH partial_update Update the notification status (mark as read) IsAuthenticated

NotificationCategoryViewSet Explanation

1. list

  • Purpose: Retrieves all notification categories.
  • Implementation:
  • Fetches all the available notification categories from the database and returns them in the response.
  • Permissions: No special permissions are required, but the user must be authenticated.

NotificationViewSet Explanation

1. Permissions

The NotificationViewSet requires the user to be authenticated. The permissions are also based on the user’s role: - Vendor: Can view their own notifications. - Vendor Role (e.g., Order Management): Can view notifications if they have permission for the specific sub-vendor. - User: Cannot view notifications.

2. list

  • Purpose: Retrieves all notifications for a specific vendor, categorized by notification type.
  • Query Parameters:
  • category: Optionally filter notifications by category name.
  • Implementation:
  • Filters notifications for the authenticated vendor.
  • Returns notifications that are marked as read and not recent.
  • Groups notifications by their category and returns them in a structured format.
  • Response: Returns grouped notifications by category.

3. partial_update

  • Purpose: Update the status of notifications, marking them as no longer recent.
  • Request Data:
  • category: The category of notifications to update.
  • Implementation:
  • Filters notifications by vendor and category.
  • Updates the is_recent_notification field of the matched notifications.
  • Returns a success message with the count of updated notifications.
  • Response: A message indicating the number of updated notifications.

Summary

The NotificationViewSet and NotificationCategoryViewSet provide a set of actions to manage notifications and notification categories in the API. Notifications are grouped by categories, and actions are available to list and update them. Permissions ensure that only authorized users can view or modify notifications, based on their role and vendor associations.