Initial commit

This commit is contained in:
2025-11-17 15:04:27 +07:00
parent fb23922d31
commit a14562cfe0
14 changed files with 640 additions and 6673 deletions

View File

@@ -3,9 +3,7 @@ package v1
import (
"api-service/internal/config"
"api-service/internal/database"
authHandlers "api-service/internal/handlers/auth"
healthcheckHandlers "api-service/internal/handlers/healthcheck"
retribusiHandlers "api-service/internal/handlers/retribusi"
websocketHandlers "api-service/internal/handlers/websocket"
"api-service/internal/middleware"
services "api-service/internal/services/auth"
@@ -22,7 +20,7 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
router := gin.New()
// Initialize auth middleware configuration
middleware.InitializeAuth(cfg)
middleware.AuthJWTMiddleware()
// Add global middleware
router.Use(middleware.CORSConfig())
@@ -90,17 +88,17 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
// =============================================================================
// Authentication routes
authHandler := authHandlers.NewAuthHandler(authService)
tokenHandler := authHandlers.NewTokenHandler(authService)
// authHandler := authHandlers.NewAuthHandler(authService)
// tokenHandler := authHandlers.NewTokenHandler(authService)
// Basic auth routes
v1.POST("/auth/login", authHandler.Login)
v1.POST("/auth/register", authHandler.Register)
v1.POST("/auth/refresh", authHandler.RefreshToken)
// v1.POST("/auth/login", authHandler.Login)
// v1.POST("/auth/register", authHandler.Register)
// v1.POST("/auth/refresh", authHandler.RefreshToken)
// Token generation routes
v1.POST("/token/generate", tokenHandler.GenerateToken)
v1.POST("/token/generate-direct", tokenHandler.GenerateTokenDirect)
// v1.POST("/token/generate", tokenHandler.GenerateToken)
// v1.POST("/token/generate-direct", tokenHandler.GenerateTokenDirect)
// =============================================================================
// WEBSOCKET ROUTES
@@ -123,52 +121,72 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
v1.GET("/ws", websocketHandler.HandleWebSocket)
v1.GET("/ws/test", websocketHandler.TestWebSocketConnection)
v1.GET("/ws/stats", websocketHandler.GetWebSocketStats)
v1.POST("/ws/broadcast/qris", websocketHandler.BroadcastQris)
v1.POST("/ws/broadcast/check", websocketHandler.BroadcastCheck)
// Retribusi endpoints with WebSocket notifications
retribusiHandler := retribusiHandlers.NewRetribusiHandler()
retribusiGroup := v1.Group("/retribusi")
{
retribusiGroup.GET("", retribusiHandler.GetRetribusi)
retribusiGroup.GET("/dynamic", retribusiHandler.GetRetribusiDynamic)
retribusiGroup.GET("/search", retribusiHandler.SearchRetribusiAdvanced)
retribusiGroup.GET("/id/:id", retribusiHandler.GetRetribusiByID)
// retribusiHandler := retribusiHandlers.NewRetribusiHandler()
// retribusiGroup := v1.Group("/retribusi")
// {
// retribusiGroup.GET("", retribusiHandler.GetRetribusi)
// retribusiGroup.GET("/dynamic", retribusiHandler.GetRetribusiDynamic)
// retribusiGroup.GET("/search", retribusiHandler.SearchRetribusiAdvanced)
// retribusiGroup.GET("/id/:id", retribusiHandler.GetRetribusiByID)
// POST/PUT/DELETE with automatic WebSocket notifications
retribusiGroup.POST("", func(c *gin.Context) {
retribusiHandler.CreateRetribusi(c)
// // POST/PUT/DELETE with automatic WebSocket notifications
// retribusiGroup.POST("", func(c *gin.Context) {
// retribusiHandler.CreateRetribusi(c)
// Trigger WebSocket notification after successful creation
if c.Writer.Status() == 200 || c.Writer.Status() == 201 {
// Notify database change via WebSocket
// websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// fmt.Sprintf(`{"action": "created", "timestamp": "%s"}`, time.Now().Format(time.RFC3339)))
}
})
// // Trigger WebSocket notification after successful creation
// if c.Writer.Status() == 200 || c.Writer.Status() == 201 {
// // Notify database change via WebSocket
// // websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// // fmt.Sprintf(`{"action": "created", "timestamp": "%s"}`, time.Now().Format(time.RFC3339)))
// }
// })
retribusiGroup.PUT("/id/:id", func(c *gin.Context) {
// id := c.Param("id")
retribusiHandler.UpdateRetribusi(c)
// retribusiGroup.PUT("/id/:id", func(c *gin.Context) {
// // id := c.Param("id")
// retribusiHandler.UpdateRetribusi(c)
// Trigger WebSocket notification after successful update
if c.Writer.Status() == 200 {
// Notify database change via WebSocket
// websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// fmt.Sprintf(`{"action": "updated", "id": "%s", "timestamp": "%s"}`, id, time.Now().Format(time.RFC3339)))
}
})
// // Trigger WebSocket notification after successful update
// if c.Writer.Status() == 200 {
// // Notify database change via WebSocket
// // websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// // fmt.Sprintf(`{"action": "updated", "id": "%s", "timestamp": "%s"}`, id, time.Now().Format(time.RFC3339)))
// }
// })
retribusiGroup.DELETE("/id/:id", func(c *gin.Context) {
// id := c.Param("id")
retribusiHandler.DeleteRetribusi(c)
// retribusiGroup.DELETE("/id/:id", func(c *gin.Context) {
// // id := c.Param("id")
// retribusiHandler.DeleteRetribusi(c)
// Trigger WebSocket notification after successful deletion
if c.Writer.Status() == 200 {
// Notify database change via WebSocket
// websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// fmt.Sprintf(`{"action": "deleted", "id": "%s", "timestamp": "%s"}`, id, time.Now().Format(time.RFC3339)))
}
})
}
// // Trigger WebSocket notification after successful deletion
// if c.Writer.Status() == 200 {
// // Notify database change via WebSocket
// // websocketHub.NotifyDatabaseChange("postgres_satudata", "retribusi_changes",
// // fmt.Sprintf(`{"action": "deleted", "id": "%s", "timestamp": "%s"}`, id, time.Now().Format(time.RFC3339)))
// }
// })
// }
// =============================================================================
// PROTECTED ROUTES (Authentication Required)
// =============================================================================
// Create protected group with configurable authentication
protected := v1.Group("/")
protected.Use(middleware.AuthJWTMiddleware()) // Use configurable authentication
// User profile (protected)
// protected.GET("/auth/me", authHandler.Me)
// Retribusi endpoints (CRUD operations - should be protected)
// protectedQris := protected.Group("/ws")
// {
// protectedQris.POST("/qris/broadcast", websocketHandler.BroadcastQris) // POST /api/v1/ws/
// protectedQris.POST("/check/broadcast", websocketHandler.BroadcastCheck) // POST /api/v1/ws/
// }
return router
}