Enhance Notification System with New API Endpoints and Response Structures
- Added new endpoints for marking notifications as seen and retrieving detailed notification information for both admin and user contexts, improving the flexibility of the notification system. - Implemented the MarkSeen and ViewNotification methods in the NotificationHandler, ensuring proper handling of notification visibility and details retrieval. - Updated the NotificationService interface to include methods for getting notification details and marking notifications as seen, enhancing service capabilities. - Enhanced the notification response structures to include additional fields such as Image, Seen, and ScheduledAt, providing richer data in API responses. - Updated API documentation with Swagger comments for the new endpoints and response formats, ensuring clarity for API consumers.
This commit is contained in:
@@ -47,7 +47,7 @@ func (h *NotificationHandler) Send(c echo.Context) error {
|
||||
}
|
||||
|
||||
// Send notification
|
||||
go h.service.Send(c.Request().Context(), &req)
|
||||
h.service.Send(c.Request().Context(), &req)
|
||||
|
||||
return response.Created(c, nil, "Notification sent successfully")
|
||||
}
|
||||
@@ -148,6 +148,65 @@ func (h *NotificationHandler) AdminNotifications(c echo.Context) error {
|
||||
return response.Success(c, notifications, "Notifications retrieved successfully")
|
||||
}
|
||||
|
||||
// MarkSeen marks a notification as seen
|
||||
// @Summary Mark a notification as seen
|
||||
// @Description Mark a notification as seen
|
||||
// @Tags Admin-Notification
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Notification ID"
|
||||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /admin/v1/notifications/mark-seen/{id} [get]
|
||||
func (h *NotificationHandler) MarkSeen(c echo.Context) error {
|
||||
notificationID := c.Param("id")
|
||||
|
||||
userID, err := user.GetUserIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
||||
}
|
||||
|
||||
// Mark notification as seen
|
||||
err = h.service.MarkSeen(c.Request().Context(), notificationID, userID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to mark notification as seen")
|
||||
}
|
||||
|
||||
return response.Success(c, nil, "Notification marked as seen successfully")
|
||||
}
|
||||
|
||||
// ViewNotification gets a single notification by ID
|
||||
// @Summary Get notification details
|
||||
// @Description Get detailed information about a specific notification
|
||||
// @Tags Admin-Notification
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Notification ID"
|
||||
// @Success 200 {object} response.APIResponse{data=NotificationResponse}
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 404 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /admin/v1/notifications/view/{id} [get]
|
||||
func (h *NotificationHandler) ViewNotification(c echo.Context) error {
|
||||
notificationID := c.Param("id")
|
||||
if notificationID == "" {
|
||||
return response.BadRequest(c, "notification ID is required", "Notification ID must be provided")
|
||||
}
|
||||
|
||||
// Get notification details
|
||||
notification, err := h.service.GetNotification(c.Request().Context(), notificationID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to get notification details")
|
||||
}
|
||||
|
||||
return response.Success(c, notification, "Notification details retrieved successfully")
|
||||
}
|
||||
|
||||
// **************************** PUBLIC ENDPOINTS ****************************
|
||||
|
||||
// MyNotifications gets notifications for the user
|
||||
// @Summary Get notifications for the user
|
||||
// @Description Get notifications for the user
|
||||
@@ -169,7 +228,7 @@ func (h *NotificationHandler) AdminNotifications(c echo.Context) error {
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/notifications/my [get]
|
||||
// @Router /api/v1/notifications [get]
|
||||
func (h *NotificationHandler) CustomerNotifications(c echo.Context) error {
|
||||
userID, err := user.GetUserIDFromContext(c)
|
||||
if err != nil {
|
||||
@@ -199,3 +258,60 @@ func (h *NotificationHandler) CustomerNotifications(c echo.Context) error {
|
||||
|
||||
return response.Success(c, notifications, "Notifications retrieved successfully")
|
||||
}
|
||||
|
||||
// MarkSeen marks a notification as seen
|
||||
// @Summary Mark a notification as seen
|
||||
// @Description Mark a notification as seen
|
||||
// @Tags Notification
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Notification ID"
|
||||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/notifications/mark-seen/{id} [get]
|
||||
func (h *NotificationHandler) PublicMarkSeen(c echo.Context) error {
|
||||
notificationID := c.Param("id")
|
||||
|
||||
userID, err := user.GetUserIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
||||
}
|
||||
|
||||
// Mark notification as seen
|
||||
err = h.service.MarkSeen(c.Request().Context(), notificationID, userID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to mark notification as seen")
|
||||
}
|
||||
|
||||
return response.Success(c, nil, "Notification marked as seen successfully")
|
||||
}
|
||||
|
||||
// ViewNotification gets a single notification by ID
|
||||
// @Summary Get notification details
|
||||
// @Description Get detailed information about a specific notification
|
||||
// @Tags Notification
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Notification ID"
|
||||
// @Success 200 {object} response.APIResponse{data=DetailedNotificationResponse}
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 404 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/notifications/view/{id} [get]
|
||||
func (h *NotificationHandler) PublicViewNotification(c echo.Context) error {
|
||||
notificationID := c.Param("id")
|
||||
if notificationID == "" {
|
||||
return response.BadRequest(c, "notification ID is required", "Notification ID must be provided")
|
||||
}
|
||||
|
||||
// Get notification details
|
||||
notification, err := h.service.GetNotification(c.Request().Context(), notificationID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to get notification details")
|
||||
}
|
||||
|
||||
return response.Success(c, notification, "Notification details retrieved successfully")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user