diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 2b41d38..b1fb9ed 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,10 @@
-
+
-
+
+
@@ -153,7 +154,6 @@
-
@@ -178,7 +178,8 @@
-
+
+
true
diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go
index 1e4cb7f..78b0365 100644
--- a/pkg/internal/server/api/index.go
+++ b/pkg/internal/server/api/index.go
@@ -18,8 +18,13 @@ func MapAPIs(app *fiber.App, baseURL string) {
notify := api.Group("/notifications").Name("Notifications API")
{
- notify.Get("/", getNotifications)
+ // Deprecated, use /subscription instead, will be removed in the future
notify.Post("/subscribe", addNotifySubscriber)
+
+ notify.Get("/", getNotifications)
+ notify.Get("/subscription", getNotifySubscriber)
+ notify.Post("/subscription", addNotifySubscriber)
+ notify.Delete("/subscription/:deviceId", removeNotifySubscriber)
notify.Put("/read", markNotificationReadBatch)
notify.Put("/read/:notificationId", markNotificationRead)
}
diff --git a/pkg/internal/server/api/notifications_api.go b/pkg/internal/server/api/notifications_api.go
index 7bbb8cb..2d22a32 100644
--- a/pkg/internal/server/api/notifications_api.go
+++ b/pkg/internal/server/api/notifications_api.go
@@ -88,6 +88,22 @@ func markNotificationReadBatch(c *fiber.Ctx) error {
}
}
+func getNotifySubscriber(c *fiber.Ctx) error {
+ if err := exts.EnsureAuthenticated(c); err != nil {
+ return err
+ }
+ user := c.Locals("user").(models.Account)
+
+ var subscribers []models.NotificationSubscriber
+ if err := database.C.Where(&models.NotificationSubscriber{
+ AccountID: user.ID,
+ }).Find(&subscribers).Error; err != nil {
+ return fiber.NewError(fiber.StatusNotFound, err.Error())
+ }
+
+ return c.JSON(subscribers)
+}
+
func addNotifySubscriber(c *fiber.Ctx) error {
if err := exts.EnsureAuthenticated(c); err != nil {
return err
@@ -126,3 +142,21 @@ func addNotifySubscriber(c *fiber.Ctx) error {
return c.JSON(subscriber)
}
+
+func removeNotifySubscriber(c *fiber.Ctx) error {
+ if err := exts.EnsureAuthenticated(c); err != nil {
+ return err
+ }
+ user := c.Locals("user").(models.Account)
+
+ device := c.Params("deviceId")
+
+ if err := database.C.Where(&models.NotificationSubscriber{
+ DeviceID: device,
+ AccountID: user.ID,
+ }).Delete(&models.NotificationSubscriber{}).Error; err != nil {
+ return fiber.NewError(fiber.StatusBadRequest, err.Error())
+ }
+
+ return c.SendStatus(fiber.StatusOK)
+}