feat: Add webhook client initialization and integration to carrier connector routes

- Add webhook package import to main.go and routes.go
- Add API_SERVER_WEBHOOK_URL and API_SERVER_WEBHOOK_API_KEY environment variable loading
- Add webhookClient initialization with NewWebhookClient in main function
- Add webhookClient parameter to setupRoutes function signature and comment
- Pass webhookClient to OrderProfileHandlerWithRepo and DeleteProfileHandlerWithRepo routes
This commit is contained in:
nutcas3
2026-04-25 05:47:37 +03:00
parent 2d891cdb2a
commit b6564dcbd1
2 changed files with 12 additions and 5 deletions
+7 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
handler "github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handler"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/webhook"
"github.com/rs/zerolog"
)
@@ -56,7 +57,12 @@ func main() {
profileRepo := repository.NewCachedProfileStore(postgresRepo, 5*time.Minute)
defer profileRepo.Close()
setupRoutes(router, client, profileRepo)
// Initialize webhook client for api-server notifications
webhookURL := handler.GetEnv("API_SERVER_WEBHOOK_URL", "")
webhookAPIKey := handler.GetEnv("API_SERVER_WEBHOOK_API_KEY", "")
webhookClient := webhook.NewWebhookClient(webhookURL, webhookAPIKey)
setupRoutes(router, client, profileRepo, webhookClient)
handler.Logger.Info().Str("port", port).Msg("Carrier Connector API server starting")
if err := router.Run(":" + port); err != nil {
+5 -4
View File
@@ -10,10 +10,11 @@ import (
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
handler "github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handler"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/webhook"
)
// setupRoutes registers all HTTP routes, wiring the ES2+ client and profile repo.
func setupRoutes(router *gin.Engine, client *es2.ES2Client, repo repository.ProfileRepository) {
// setupRoutes registers all HTTP routes, wiring the ES2+ client, profile repo, and webhook client.
func setupRoutes(router *gin.Engine, client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient) {
api := router.Group("/api/v1")
api.GET("/health", healthHandler)
api.GET("/health/ready", readinessHandler(repo))
@@ -22,10 +23,10 @@ func setupRoutes(router *gin.Engine, client *es2.ES2Client, repo repository.Prof
esim := api.Group("/esim")
{
esim.POST("/profiles", handler.OrderProfileHandlerWithRepo(client, repo))
esim.POST("/profiles", handler.OrderProfileHandlerWithRepo(client, repo, webhookClient))
esim.GET("/profiles", handler.ListProfilesHandlerWithRepo(repo))
esim.GET("/profiles/:profileId", handler.GetProfileHandlerWithRepo(client, repo))
esim.DELETE("/profiles/:profileId", handler.DeleteProfileHandlerWithRepo(client, repo))
esim.DELETE("/profiles/:profileId", handler.DeleteProfileHandlerWithRepo(client, repo, webhookClient))
}
carrier := api.Group("/carrier")