package handlers import ( "net/http" "strconv" "github.com/gin-gonic/gin" "github.com/patbritton/sojorn-backend/internal/repository" ) type NotificationHandler struct { repo *repository.NotificationRepository } func NewNotificationHandler(repo *repository.NotificationRepository) *NotificationHandler { return &NotificationHandler{repo: repo} } func (h *NotificationHandler) GetNotifications(c *gin.Context) { userIdStr, exists := c.Get("user_id") if !exists { c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"}) return } limit := 20 offset := 0 if l := c.Query("limit"); l != "" { if val, err := strconv.Atoi(l); err == nil { limit = val } } if o := c.Query("offset"); o != "" { if val, err := strconv.Atoi(o); err == nil { offset = val } } notifications, err := h.repo.GetNotifications(c.Request.Context(), userIdStr.(string), limit, offset) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch notifications"}) return } c.JSON(http.StatusOK, notifications) }