File size: 2,015 Bytes
973ad5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package handler
import (
"github.com/danielgtaylor/huma/v2"
"github.com/axyut/niyamAPI/internal/config" // Adjust import path
"github.com/axyut/niyamAPI/internal/service" // Adjust import path
// Adjust import path
"github.com/axyut/niyamAPI/internal/db" // Adjust import path to your module
)
// Handlers holds dependencies for all API handlers.
// This struct will be initialized once in main.go and passed to all handler
// registration functions. It centralizes access to configuration, business
// services, and the database client.
type Handlers struct {
AppConfig *config.AppConfig // Application-wide configuration
Services *service.Services // Business logic services layer
DBClient *db.Client // MongoDB client for database operations/health checks
}
// NewHandlers creates a new Handlers instance.
// It takes instances of your configuration, services, and database client
// as dependencies, setting them up for use across all API handlers.
func NewHandlers(cfg *config.AppConfig, svc *service.Services, dbClient *db.Client) *Handlers {
return &Handlers{
AppConfig: cfg,
Services: svc,
DBClient: dbClient, // Pass the initialized MongoDB client here
}
}
// RegisterHandlers registers all API endpoints with the Huma API instance.
// This method orchestrates the registration of handlers from different logical
// groups (e.g., home, user, goods).
func (h *Handlers) RegisterHandlers(api huma.API) {
// Register handlers for the root ("/") and health ("healthz") endpoints.
h.RegisterHomeHandlers(api)
h.RegisterUserHandlers(api)
// --- Placeholder for registering other domain-specific handlers ---
// As you implement more features (e.g., for users, goods, transactions),
// you would call their respective registration methods here.
// Example:
// h.RegisterUserHandlers(api)
// h.RegisterGoodsHandlers(api)
// h.RegisterTransactionHandlers(api)
// h.RegisterProductionHandlers(api)
// h.RegisterReportsHandlers(api)
// h.RegisterAudienceHandlers(api)
}
|