⚡ A separate API to only get notification count
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user