Files
quyun-v2/backend/app/http/super/v1/notifications.go

92 lines
3.1 KiB
Go

package v1
import (
dto "quyun/v2/app/http/super/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
)
// @provider
type notifications struct{}
// List notifications
//
// @Router /super/v1/notifications [get]
// @Summary List notifications
// @Description List notifications across tenants
// @Tags Notification
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.SuperNotificationItem}
// @Bind filter query
func (c *notifications) List(ctx fiber.Ctx, filter *dto.SuperNotificationListFilter) (*requests.Pager, error) {
return services.Super.ListNotifications(ctx, filter)
}
// Broadcast notification
//
// @Router /super/v1/notifications/broadcast [post]
// @Summary Broadcast notification
// @Description Broadcast notification to users or tenant members
// @Tags Notification
// @Accept json
// @Produce json
// @Param form body dto.SuperNotificationBroadcastForm true "Broadcast form"
// @Success 200 {string} string "Sent"
// @Bind form body
func (c *notifications) Broadcast(ctx fiber.Ctx, form *dto.SuperNotificationBroadcastForm) error {
return services.Super.BroadcastNotifications(ctx, form)
}
// List notification templates
//
// @Router /super/v1/notifications/templates [get]
// @Summary List notification templates
// @Description List notification templates
// @Tags Notification
// @Accept json
// @Produce json
// @Success 200 {object} requests.Pager{items=[]dto.SuperNotificationTemplateItem}
// @Bind filter query
func (c *notifications) ListTemplates(ctx fiber.Ctx, filter *dto.SuperNotificationTemplateListFilter) (*requests.Pager, error) {
return services.Super.ListNotificationTemplates(ctx, filter)
}
// Create notification template
//
// @Router /super/v1/notifications/templates [post]
// @Summary Create notification template
// @Description Create notification template
// @Tags Notification
// @Accept json
// @Produce json
// @Param form body dto.SuperNotificationTemplateCreateForm true "Template form"
// @Success 200 {object} dto.SuperNotificationTemplateItem
// @Bind form body
func (c *notifications) CreateTemplate(ctx fiber.Ctx, form *dto.SuperNotificationTemplateCreateForm) (*dto.SuperNotificationTemplateItem, error) {
return services.Super.CreateNotificationTemplate(ctx, form)
}
// Update notification template
//
// @Router /super/v1/notifications/templates/:id<int> [patch]
// @Summary Update notification template
// @Description Update notification template
// @Tags Notification
// @Accept json
// @Produce json
// @Param id path int64 true "Template ID"
// @Param form body dto.SuperNotificationTemplateUpdateForm true "Update form"
// @Success 200 {object} dto.SuperNotificationTemplateItem
// @Bind user local key(__ctx_user)
// @Bind id path
// @Bind form body
func (c *notifications) UpdateTemplate(ctx fiber.Ctx, user *models.User, id int64, form *dto.SuperNotificationTemplateUpdateForm) (*dto.SuperNotificationTemplateItem, error) {
return services.Super.UpdateNotificationTemplate(ctx, user.ID, id, form)
}