✨ Notification preferences
This commit is contained in:
@ -24,6 +24,12 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
notify.Put("/read/:notificationId", markNotificationRead)
|
||||
}
|
||||
|
||||
preferences := api.Group("/preferences").Name("Preferences API")
|
||||
{
|
||||
preferences.Get("/notifications", getNotificationPreference)
|
||||
preferences.Put("/notifications", updateNotificationPreference)
|
||||
}
|
||||
|
||||
api.Get("/users/lookup", lookupAccount)
|
||||
api.Get("/users/search", searchAccount)
|
||||
|
||||
|
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||
@ -52,6 +53,7 @@ func notifyUser(c *fiber.Ctx) error {
|
||||
Picture: data.Picture,
|
||||
IsRealtime: data.IsRealtime,
|
||||
IsForcePush: data.IsForcePush,
|
||||
Account: target,
|
||||
AccountID: target.ID,
|
||||
SenderID: &client.ID,
|
||||
}
|
||||
|
43
pkg/internal/server/api/preferences_api.go
Normal file
43
pkg/internal/server/api/preferences_api.go
Normal file
@ -0,0 +1,43 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func getNotificationPreference(c *fiber.Ctx) error {
|
||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
}
|
||||
user := c.Locals("user").(models.Account)
|
||||
notification, err := services.GetNotificationPreference(user)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(notification)
|
||||
}
|
||||
|
||||
func updateNotificationPreference(c *fiber.Ctx) error {
|
||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
}
|
||||
user := c.Locals("user").(models.Account)
|
||||
|
||||
var data struct {
|
||||
Config map[string]bool `json:"config"`
|
||||
}
|
||||
|
||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
notification, err := services.UpdateNotificationPreference(user, data.Config)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(notification)
|
||||
}
|
Reference in New Issue
Block a user