package api import ( "devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/config" "devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/api/handlers" "devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/api/middleware" "devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/auth" "devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/proxy" "github.com/gin-gonic/gin" "go.uber.org/zap" ) // TODO: Refactor dari gin dengan chi // SetupRouter configures and returns the API router func SetupRouter(cfg *config.Config, logger *zap.Logger) *gin.Engine { // Set Gin mode if cfg.LogLevel == "debug" { gin.SetMode(gin.DebugMode) } else { gin.SetMode(gin.ReleaseMode) } // Initialize the router r := gin.New() // Add middleware r.Use(gin.Recovery()) r.Use(middleware.Logger(logger)) r.Use(middleware.CORS(cfg.AllowedOrigins)) // Setup health check r.GET("/health", handlers.HealthCheck) // Initialize Google auth client googleAuth, err := auth.NewGoogleClient(cfg.Google.CredentialsPath) if err != nil { logger.Fatal("Failed to initialize Google auth client", zap.Error(err)) } // Initialize Healthcare API client healthcareClient := proxy.NewClient(googleAuth, cfg.Google) // DICOM Web routes dicomGroup := r.Group("/dicomWeb") { dicomHandler := handlers.NewDicomHandler(healthcareClient, logger) // Add audit logging middleware to DICOM routes dicomGroup.Use(middleware.AuditLog(logger)) // WADO routes dicomGroup.Any("/wado/*path", dicomHandler.ForwardRequest) // QIDO routes dicomGroup.Any("/qido/*path", dicomHandler.ForwardRequest) // STOW routes dicomGroup.Any("/stow/*path", dicomHandler.ForwardRequest) } // Future auth routes for doctors authGroup := r.Group("/auth") { // Auth handlers will be implemented later authHandler := handlers.NewAuthHandler(logger) authGroup.POST("/login", authHandler.Login) authGroup.POST("/logout", authHandler.Logout) } return r }