Notification list

This commit is contained in:
2024-03-16 12:28:50 +08:00
parent d28a79fdd9
commit fa59f87d3c
6 changed files with 146 additions and 37 deletions

View File

@ -1,15 +1,16 @@
package server
import (
"fmt"
"strconv"
"time"
"code.smartsheep.studio/hydrogen/identity/pkg/database"
"code.smartsheep.studio/hydrogen/identity/pkg/models"
"code.smartsheep.studio/hydrogen/identity/pkg/services"
"fmt"
"github.com/gofiber/fiber/v2"
jsoniter "github.com/json-iterator/go"
"github.com/spf13/viper"
"strconv"
"time"
)
func getUserinfo(c *fiber.Ctx) error {
@ -20,7 +21,6 @@ func getUserinfo(c *fiber.Ctx) error {
Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}).
Preload("Profile").
Preload("Contacts").
Preload("Notifications", "read_at IS NULL").
First(&data).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}

View File

@ -1,12 +1,13 @@
package server
import (
"time"
"code.smartsheep.studio/hydrogen/identity/pkg/database"
"code.smartsheep.studio/hydrogen/identity/pkg/models"
"code.smartsheep.studio/hydrogen/identity/pkg/services"
"github.com/gofiber/fiber/v2"
"github.com/samber/lo"
"time"
)
func getNotifications(c *fiber.Ctx) error {
@ -14,7 +15,7 @@ func getNotifications(c *fiber.Ctx) error {
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
only_unread := c.QueryBool("only_unread", true)
only_unread := !c.QueryBool("past", false)
tx := database.C.Where(&models.Notification{RecipientID: user.ID}).Model(&models.Notification{})
if only_unread {