mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-04 19:02:19 +00:00
feat: Add webhook notifications to carrier connector profile operations
- Add webhookClient parameter to OrderProfileHandlerWithRepo and DeleteProfileHandlerWithRepo - Add SendDownloadFailed webhook notification on profile order failure with error details - Add SendProfileDownloaded webhook notification on successful profile download with IMSI, profileType, and status - Add SendProfileDeleted webhook notification on profile deletion with executionStatus and statusMessage - Add webhook package import
This commit is contained in:
@@ -11,10 +11,11 @@ import (
|
|||||||
|
|
||||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
|
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
|
||||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
|
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
|
||||||
|
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/webhook"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OrderProfileHandlerWithRepo orders a profile via ES2+ and persists it in the repo.
|
// OrderProfileHandlerWithRepo orders a profile via ES2+ and persists it in the repo.
|
||||||
func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository) gin.HandlerFunc {
|
func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var order ProfileOrder
|
var order ProfileOrder
|
||||||
if err := c.ShouldBindJSON(&order); err != nil {
|
if err := c.ShouldBindJSON(&order); err != nil {
|
||||||
@@ -44,6 +45,12 @@ func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileR
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Error().Err(err).Str("imsi", order.IMSI).Msg("Failed to order profile")
|
Logger.Error().Err(err).Str("imsi", order.IMSI).Msg("Failed to order profile")
|
||||||
|
|
||||||
|
// Send webhook notification for failed download
|
||||||
|
if webhookClient != nil {
|
||||||
|
go webhookClient.SendDownloadFailed(context.Background(), order.ICCID, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to order profile", "message": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to order profile", "message": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -62,6 +69,15 @@ func OrderProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileR
|
|||||||
Logger.Warn().Err(err).Str("iccid", order.ICCID).Msg("Profile repo write failed")
|
Logger.Warn().Err(err).Str("iccid", order.ICCID).Msg("Profile repo write failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send webhook notification for successful download
|
||||||
|
if webhookClient != nil {
|
||||||
|
go webhookClient.SendProfileDownloaded(context.Background(), order.ICCID, map[string]interface{}{
|
||||||
|
"imsi": order.IMSI,
|
||||||
|
"profileType": order.ProfileType,
|
||||||
|
"status": downloadResp.ExecutionStatus,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"profile": &ProfileResponse{
|
"profile": &ProfileResponse{
|
||||||
@@ -157,7 +173,7 @@ func ListProfilesHandlerWithRepo(repo repository.ProfileRepository) gin.HandlerF
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteProfileHandlerWithRepo deletes a profile from the SM-DP+ and marks it deleted in the repo.
|
// DeleteProfileHandlerWithRepo deletes a profile from the SM-DP+ and marks it deleted in the repo.
|
||||||
func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository) gin.HandlerFunc {
|
func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.ProfileRepository, webhookClient *webhook.WebhookClient) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
profileID := c.Param("profileId")
|
profileID := c.Param("profileId")
|
||||||
if profileID == "" {
|
if profileID == "" {
|
||||||
@@ -176,6 +192,14 @@ func DeleteProfileHandlerWithRepo(client *es2.ES2Client, repo repository.Profile
|
|||||||
Logger.Warn().Err(err).Str("profile_id", profileID).Msg("Profile repo update failed")
|
Logger.Warn().Err(err).Str("profile_id", profileID).Msg("Profile repo update failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send webhook notification for profile deletion
|
||||||
|
if webhookClient != nil {
|
||||||
|
go webhookClient.SendProfileDeleted(context.Background(), profileID, map[string]interface{}{
|
||||||
|
"executionStatus": deleteResp.ExecutionStatus,
|
||||||
|
"statusMessage": deleteResp.StatusMessage,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "Profile deletion requested",
|
"message": "Profile deletion requested",
|
||||||
|
|||||||
Reference in New Issue
Block a user