diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6b83b28..ef95159 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,10 @@
-
+
+
@@ -159,7 +160,6 @@
-
@@ -184,7 +184,8 @@
-
+
+
diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go
index 6374142..55fdbeb 100644
--- a/pkg/internal/http/api/index.go
+++ b/pkg/internal/http/api/index.go
@@ -20,6 +20,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
notify := api.Group("/notifications").Name("Notifications API")
{
notify.Get("/", getNotifications)
+ notify.Get("/count", getNotificationCount)
notify.Get("/subscription", getNotifySubscriber)
notify.Post("/subscription", addNotifySubscriber)
notify.Delete("/subscription/:deviceId", removeNotifySubscriber)
diff --git a/pkg/internal/http/api/notifications_api.go b/pkg/internal/http/api/notifications_api.go
index 907de5d..204bada 100644
--- a/pkg/internal/http/api/notifications_api.go
+++ b/pkg/internal/http/api/notifications_api.go
@@ -43,6 +43,25 @@ func getNotifications(c *fiber.Ctx) error {
})
}
+func getNotificationCount(c *fiber.Ctx) error {
+ if err := exts.EnsureAuthenticated(c); err != nil {
+ return err
+ }
+ user := c.Locals("user").(models.Account)
+
+ tx := database.C.Where(&models.Notification{AccountID: user.ID}).Model(&models.Notification{})
+
+ var count int64
+ if err := tx.
+ Count(&count).Error; err != nil {
+ return fiber.NewError(fiber.StatusInternalServerError, err.Error())
+ }
+
+ return c.JSON(fiber.Map{
+ "count": count,
+ })
+}
+
func markNotificationRead(c *fiber.Ctx) error {
if err := exts.EnsureAuthenticated(c); err != nil {
return err