⚡ A separate API to only get notification count
This commit is contained in:
parent
0115e6723a
commit
fdf2d28f51
7
.idea/workspace.xml
generated
7
.idea/workspace.xml
generated
@ -4,9 +4,10 @@
|
|||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":zap: Add cache into querying user">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix missing api endpoint">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/index.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/index.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/internal/http/api/notifications_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/notifications_api.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -159,7 +160,6 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||||
<MESSAGE value=":bug: Fix notifiable is empty when user do not set" />
|
|
||||||
<MESSAGE value=":bug: Fix notification push batch emitted twice" />
|
<MESSAGE value=":bug: Fix notification push batch emitted twice" />
|
||||||
<MESSAGE value=":sparkles: Support jwks.json according OIDC stranded" />
|
<MESSAGE value=":sparkles: Support jwks.json according OIDC stranded" />
|
||||||
<MESSAGE value=":bug: Fix get user grpc method didn't extend group's permission" />
|
<MESSAGE value=":bug: Fix get user grpc method didn't extend group's permission" />
|
||||||
@ -184,7 +184,8 @@
|
|||||||
<MESSAGE value=":bug: Bug fix directory service wasn't registered" />
|
<MESSAGE value=":bug: Bug fix directory service wasn't registered" />
|
||||||
<MESSAGE value=":bug: Fix random panic" />
|
<MESSAGE value=":bug: Fix random panic" />
|
||||||
<MESSAGE value=":zap: Add cache into querying user" />
|
<MESSAGE value=":zap: Add cache into querying user" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value=":zap: Add cache into querying user" />
|
<MESSAGE value=":bug: Fix missing api endpoint" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix missing api endpoint" />
|
||||||
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
|
@ -20,6 +20,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
notify := api.Group("/notifications").Name("Notifications API")
|
notify := api.Group("/notifications").Name("Notifications API")
|
||||||
{
|
{
|
||||||
notify.Get("/", getNotifications)
|
notify.Get("/", getNotifications)
|
||||||
|
notify.Get("/count", getNotificationCount)
|
||||||
notify.Get("/subscription", getNotifySubscriber)
|
notify.Get("/subscription", getNotifySubscriber)
|
||||||
notify.Post("/subscription", addNotifySubscriber)
|
notify.Post("/subscription", addNotifySubscriber)
|
||||||
notify.Delete("/subscription/:deviceId", removeNotifySubscriber)
|
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 {
|
func markNotificationRead(c *fiber.Ctx) error {
|
||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user