mengstack-api/internal/modules/notification/interfaces/routes.go
MengStack Dev cb7ad4d35d feat(notification): M6 示例模块 + 单元测试
Complete 4-layer notification module as reference template:
domain → infrastructure → application → interfaces.
10 unit tests covering all service methods with mock repository.
2026-10-03 01:07:10 +08:00

44 lines
1.1 KiB
Go

package interfaces
import (
"mengstack/internal/app/middleware"
"mengstack/internal/modules/notification/application"
"mengstack/internal/modules/notification/infrastructure"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
"go.uber.org/zap"
"gorm.io/gorm"
)
func SetupRoutes(
r *gin.Engine,
h *Handler,
authMW gin.HandlerFunc,
) {
notifications := r.Group("/api/v1/notifications")
notifications.Use(authMW, middleware.MultiTenant())
{
notifications.POST("", h.Create)
notifications.GET("/:id", h.Get)
notifications.DELETE("/:id", h.Delete)
notifications.PUT("/:id/read", h.MarkAsRead)
notifications.PUT("/read-all", h.MarkAllAsRead)
notifications.GET("/unread-count", h.CountUnread)
notifications.GET("/user/:userId", h.ListByUser)
}
}
var Module = fx.Module("notification",
fx.Provide(
infrastructure.NewNotificationRepository,
application.NewService,
NewHandler,
),
fx.Invoke(func(db *gorm.DB, log *zap.Logger) {
if err := infrastructure.Migrate(db); err != nil {
log.Fatal("notification migration failed", zap.Error(err))
}
}),
)