Refactor Notification Handler to Use Customer Context for User ID Retrieval
- Updated the CustomerNotifications and PublicMarkSeen methods in NotificationHandler to retrieve the customer ID from context instead of the user ID, aligning with the new customer-centric approach. - This change enhances the integration between notifications and customer management, ensuring that notifications are correctly associated with customers. - Maintained existing error handling for missing customer ID, ensuring robustness in the notification retrieval process.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/asaskevich/govalidator"
|
"github.com/asaskevich/govalidator"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
||||||
|
"tm/internal/customer"
|
||||||
"tm/internal/user"
|
"tm/internal/user"
|
||||||
"tm/pkg/logger"
|
"tm/pkg/logger"
|
||||||
"tm/pkg/response"
|
"tm/pkg/response"
|
||||||
@@ -230,7 +231,7 @@ func (h *NotificationHandler) ViewNotification(c echo.Context) error {
|
|||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Router /api/v1/notifications [get]
|
// @Router /api/v1/notifications [get]
|
||||||
func (h *NotificationHandler) CustomerNotifications(c echo.Context) error {
|
func (h *NotificationHandler) CustomerNotifications(c echo.Context) error {
|
||||||
userID, err := user.GetUserIDFromContext(c)
|
userID, err := customer.GetCustomerIDFromContext(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
||||||
}
|
}
|
||||||
@@ -274,7 +275,7 @@ func (h *NotificationHandler) CustomerNotifications(c echo.Context) error {
|
|||||||
func (h *NotificationHandler) PublicMarkSeen(c echo.Context) error {
|
func (h *NotificationHandler) PublicMarkSeen(c echo.Context) error {
|
||||||
notificationID := c.Param("id")
|
notificationID := c.Param("id")
|
||||||
|
|
||||||
userID, err := user.GetUserIDFromContext(c)
|
userID, err := customer.GetCustomerIDFromContext(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
return response.BadRequest(c, "User ID required", "User must be associated with a user")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user