- Created `qa-test-output-after-fix.txt` and `qa-test-output.txt` to log results of certificate page authentication tests. - Added `build.sh` for deterministic backend builds in CI, utilizing `go list` for efficiency. - Introduced `codeql_scan.sh` for CodeQL database creation and analysis for Go and JavaScript/TypeScript. - Implemented `dockerfile_check.sh` to validate Dockerfiles for base image and package manager mismatches. - Added `sourcery_precommit_wrapper.sh` to facilitate Sourcery CLI usage in pre-commit hooks.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Wikid82/charon/backend/internal/services"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type NotificationHandler struct {
|
|
service *services.NotificationService
|
|
}
|
|
|
|
func NewNotificationHandler(service *services.NotificationService) *NotificationHandler {
|
|
return &NotificationHandler{service: service}
|
|
}
|
|
|
|
func (h *NotificationHandler) List(c *gin.Context) {
|
|
unreadOnly := c.Query("unread") == "true"
|
|
notifications, err := h.service.List(unreadOnly)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to list notifications"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, notifications)
|
|
}
|
|
|
|
func (h *NotificationHandler) MarkAsRead(c *gin.Context) {
|
|
id := c.Param("id")
|
|
if err := h.service.MarkAsRead(id); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to mark notification as read"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"message": "Notification marked as read"})
|
|
}
|
|
|
|
func (h *NotificationHandler) MarkAllAsRead(c *gin.Context) {
|
|
if err := h.service.MarkAllAsRead(); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to mark all notifications as read"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"message": "All notifications marked as read"})
|
|
}
|