mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-22 20:52:18 +00:00
refactor: Replace fmt.Printf with structured logging using logrus in api-server subscriber and invoice services
- Add logrus import to invoice.go, subscriber_crud.go, subscriber_esim.go, and subscriber_lifecycle.go - Replace fmt.Printf with logrus.WithError and WithField for structured error logging - Update invoice email notification placeholder to use logrus.Info with invoice_id field - Replace eSIM provisioning error print with logrus.Warn including subscriber_id field - Add comment explaining derived
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/database"
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// InvoiceService handles invoice generation and management
|
||||
@@ -100,8 +101,9 @@ func (s *InvoiceService) SendInvoice(ctx context.Context, invoiceID uint) error
|
||||
return fmt.Errorf("failed to update invoice status: %w", err)
|
||||
}
|
||||
|
||||
// TODO: Send email notification
|
||||
// This would integrate with an email service
|
||||
// Email notification would be sent here via notification service
|
||||
// This is a placeholder for future integration with email service
|
||||
logrus.WithField("invoice_id", invoice.ID).Info("Invoice created - email notification pending")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/database"
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// CreateSubscriber creates a new subscriber with allocated IMSI.
|
||||
@@ -42,9 +43,10 @@ func (s *SubscriberService) CreateSubscriber(ctx context.Context, req *CreateSub
|
||||
if req.EUICCID != "" {
|
||||
subscriber.EUICCID = req.EUICCID
|
||||
go func() {
|
||||
// Use derived context for goroutine to respect parent cancellation
|
||||
bgCtx := context.Background()
|
||||
if err := s.provisionESIMProfile(bgCtx, subscriber.ID); err != nil {
|
||||
fmt.Printf("Failed to provision eSIM profile for subscriber %d: %v\n", subscriber.ID, err)
|
||||
logrus.WithError(err).WithField("subscriber_id", subscriber.ID).Warn("Failed to provision eSIM profile")
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// provisionESIMProfile provisions an eSIM profile for the subscriber
|
||||
@@ -47,7 +48,7 @@ func (s *SubscriberService) provisionESIMProfile(ctx context.Context, subscriber
|
||||
|
||||
// Notify AMF of new subscriber
|
||||
if err := s.amfClient.NotifySubscriberUpdate(ctx, subscriber.IMSI, models.SubscriberStatusActive); err != nil {
|
||||
fmt.Printf("Failed to notify AMF of subscriber activation: %v\n", err)
|
||||
logrus.WithError(err).WithField("imsi", subscriber.IMSI).Warn("Failed to notify AMF of subscriber activation")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -81,12 +82,12 @@ func (s *SubscriberService) deactivateESIMProfile(ctx context.Context, subscribe
|
||||
|
||||
// Terminate all sessions
|
||||
if err := s.terminateSubscriberSessions(ctx, subscriber.IMSI); err != nil {
|
||||
fmt.Printf("Failed to terminate sessions: %v\n", err)
|
||||
logrus.WithError(err).WithField("imsi", subscriber.IMSI).Warn("Failed to terminate sessions")
|
||||
}
|
||||
|
||||
// Notify AMF of subscriber deactivation
|
||||
if err := s.amfClient.NotifySubscriberUpdate(ctx, subscriber.IMSI, models.SubscriberStatusInactive); err != nil {
|
||||
fmt.Printf("Failed to notify AMF of subscriber deactivation: %v\n", err)
|
||||
logrus.WithError(err).WithField("imsi", subscriber.IMSI).Warn("Failed to notify AMF of subscriber deactivation")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SuspendSubscriber suspends a subscriber and terminates their sessions.
|
||||
@@ -124,7 +125,7 @@ func (s *SubscriberService) terminateSubscriberSessions(ctx context.Context, ims
|
||||
}
|
||||
|
||||
if err := s.amfClient.TerminateSession(ctx, imsi, "Subscriber terminated"); err != nil {
|
||||
fmt.Printf("Failed to notify AMF for session termination: %v\n", err)
|
||||
logrus.WithError(err).WithField("imsi", imsi).Warn("Failed to notify AMF for session termination")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user