wms-be/modules/logs/routes.go

34 lines
1.2 KiB
Go

package logs
import (
"github.com/Caknoooo/go-gin-clean-starter/middlewares"
"github.com/Caknoooo/go-gin-clean-starter/modules/auth/service"
"github.com/Caknoooo/go-gin-clean-starter/modules/logs/controller"
userService "github.com/Caknoooo/go-gin-clean-starter/modules/user/service"
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
"github.com/gin-gonic/gin"
"github.com/samber/do"
)
func RegisterRoutes(server *gin.Engine, injector *do.Injector) {
logsController := do.MustInvoke[controller.LogsController](injector)
userService := do.MustInvoke[userService.UserService](injector)
jwtService := do.MustInvokeNamed[service.JWTService](injector, constants.JWTService)
// Public routes (tanpa auth) - untuk testing
publicLogs := server.Group("/logs")
{
publicLogs.GET("", logsController.GetLogs)
publicLogs.GET("/:month", logsController.GetLogsByMonth)
}
// Protected routes (hanya superadmin)
protectedLogs := server.Group("/admin/logs")
protectedLogs.Use(middlewares.Authenticate(jwtService))
protectedLogs.Use(middlewares.RoleSuperAdmin(userService))
{
protectedLogs.GET("", logsController.GetLogs)
protectedLogs.GET("/:month", logsController.GetLogsByMonth)
}
}