Generete Module Handler

This commit is contained in:
2025-08-15 15:07:38 +07:00
parent a64cbf4438
commit 66f6d0a83b
24 changed files with 1977 additions and 2369 deletions

View File

@@ -4,9 +4,11 @@ import (
"net/http"
"api-service/internal/config"
"api-service/internal/handlers"
authHandlers "api-service/internal/handlers/auth"
componentHandlers "api-service/internal/handlers/component"
employeeHandlers "api-service/internal/handlers/employee"
"api-service/internal/middleware"
"api-service/internal/services"
services "api-service/internal/services/auth"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
@@ -34,13 +36,13 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
{
// Public routes (no authentication required)
// Health endpoints
healthHandler := handlers.NewHealthHandler()
healthHandler := componentHandlers.NewHealthHandler()
v1.GET("/health", healthHandler.GetHealth)
v1.GET("/", healthHandler.HelloWorld)
// Authentication routes
authHandler := handlers.NewAuthHandler(authService)
tokenHandler := handlers.NewTokenHandler(authService)
authHandler := authHandlers.NewAuthHandler(authService)
tokenHandler := authHandlers.NewTokenHandler(authService)
v1.POST("/auth/login", authHandler.Login)
v1.POST("/auth/register", authHandler.Register)
@@ -52,11 +54,20 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
v1.POST("/token/generate-direct", tokenHandler.GenerateTokenDirect)
// Protected routes (require authentication)
// Employee endpoints
employeeHandler := employeeHandlers.NewEmployeeHandler()
v1.GET("/employees", employeeHandler.GetEmployee)
v1.GET("/employees/:id", employeeHandler.GetEmployeeByID)
v1.POST("/employees", employeeHandler.CreateEmployee)
v1.PUT("/employees/:id", employeeHandler.UpdateEmployee)
v1.DELETE("/employees/:id", employeeHandler.DeleteEmployee)
protected := v1.Group("/")
protected.Use(middleware.JWTAuthMiddleware(authService))
{
// Product endpoints
productHandler := handlers.NewProductHandler()
productHandler := componentHandlers.NewProductHandler()
protected.GET("/products", productHandler.GetProduct)
protected.GET("/products/:id", productHandler.GetProductByID)
protected.POST("/products", productHandler.CreateProduct)
@@ -64,7 +75,7 @@ func RegisterRoutes(cfg *config.Config) *gin.Engine {
protected.DELETE("/products/:id", productHandler.DeleteProduct)
// Example endpoints
exampleHandler := handlers.NewExampleHandler()
exampleHandler := componentHandlers.NewExampleHandler()
protected.GET("/example", exampleHandler.GetExample)
protected.POST("/example", exampleHandler.PostExample)